在 extjs 树存储中搜索
我的树工具栏中有一个文本字段,它应该从用户那里获取一个字符串,然后通过树的特定列进行搜索。我使用存储过滤器,但我的代码有问题,我不知道它是什么。谢谢你的帮助。 这是我的代码:
var onSimpleSearch = function(){
var searchStr= Ext.getCmp('searchField').getValue();
if(searchStr){
var tree = Ext.getCmp('infra_tree');
var tstore = tree.getStore();
var searchReg = new RegExp(".*" + searchStr + ".*", "ig");
console.log(searchReg); //return RegExp!!!!!!!
tstore.filter("ipadd", searchReg});
}else {
Ext.MessageBox.show({
title: 'Nothing to search',
msg: 'Search string is empty',
icon : 'ext-mb-info',
buttons: Ext.MessageBox.OK
});
}
};
I have a textfield in my tree toolbar that should take a string from a user then search that through a specific column of tree. I use store filter but there is a problem in my code and I dont know what it is. thanks for help.
This is my code:
var onSimpleSearch = function(){
var searchStr= Ext.getCmp('searchField').getValue();
if(searchStr){
var tree = Ext.getCmp('infra_tree');
var tstore = tree.getStore();
var searchReg = new RegExp(".*" + searchStr + ".*", "ig");
console.log(searchReg); //return RegExp!!!!!!!
tstore.filter("ipadd", searchReg});
}else {
Ext.MessageBox.show({
title: 'Nothing to search',
msg: 'Search string is empty',
icon : 'ext-mb-info',
buttons: Ext.MessageBox.OK
});
}
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Ext.data.TreeStore
中没有filter
方法(假设你使用的是 4.x,我使用的是 4.1.3)。也许这会对您有所帮助:
Ext JS 4:过滤 TreeStore
或者,您可以尝试这样的操作:
希望最后一次编辑:-)
在 Sencha 论坛的这个帖子中,他们建议您在根节点上使用
CascadeBy
。其工作原理与上面的代码或多或少相同。http://www.sencha.com/ forum/showthread.php?150060-Search-inside-extjs-tree-store
There is no
filter
method inExt.data.TreeStore
(assuming you are using 4.x, I am using 4.1.3).Maybe this will help you:
Ext JS 4: Filtering a TreeStore
Alternatively, you could try something like this:
And hopefully one last edit :-)
In this thread in the Sencha forums, they are suggesting you use
CascadeBy
on the root node. Works same way as the code above more or less.http://www.sencha.com/forum/showthread.php?150060-Search-inside-extjs-tree-store
您可以遍历树中的所有子节点,而不是遍历商店。树的所有节点都实现 TreeNodeInterface其中有您需要的方法。
cascadeBy
方法可能就是您正在寻找的方法。它将在节点的每个子节点上递归调用函数。这本质上与商店的过滤器相同,但它知道树的层次结构。显然,您也可以搜索 childNode 中的任何其他字段。通常,我保留在树中的节点具有不同的模型。如果我有一个显示在树中的
teacher
模型,那么我就有一个包含teacher
的teacherTreeModel
。所以教师树模型不保存在数据库中,只保存教师模型。发现在很多情况下这更容易。You could walk over all child nodes in the tree instead of going through the store. All nodes of the tree implement the TreeNodeInterface which has the methods you need. The
cascadeBy
method is probably what you are looking for. It will call a function recursively on each child node of a node. That is essentially the same as a filter for a store, but it knows about the hierarchy of the tree.You could search any other field in childNode as well obviously. Usually I the nodes I keep in trees have a different model in them. If I have a
teacher
model that is displayed in a tree I have ateacherTreeModel
that has ateacher
. So the teacher tree model is not saved in database, only the teacher model. Found that to be easier in many cases.我有同样的问题,我刚刚找到了一个解决“在树存储中搜索”问题的小提琴。我不知道是谁写的,但它是一个宝石。它在这里运行:https - 添加冒号斜杠斜杠 - fiddle.sencha.com/#fiddle/ra&view/editor
(我试图将此处小提琴的源代码包含到答案中,但 Stack Overflow 编辑器不允许我这样做。)
I had the same questions and I just found a fiddle that solves the "search in a tree store" problem. I don't know who wrote it, but it's a gem. It is running here: https - add colon slash slash - fiddle.sencha.com/#fiddle/ra&view/editor
(I tried to include the source code from the fiddle here into the answer, but the Stack Overflow editor doesn't allow me.)