javascript 如何在 ExtJs 的面板中搜索孩子
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9158613/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to search for a child in a panel in ExtJs
提问by hop
How can I find if a particular child (item) exists in a panel using the id of the child.
如何使用子项的 id 查找面板中是否存在特定子项(项目)。
Say I have a parent paned (id = parentPanel
) and few panels as items of this parent panel. Now, I would like to search if a panel by id 'childPanel09
' is a child of parent panel.
假设我有一个父id = parentPanel
面板( ) 和几个面板作为该父面板的项目。现在,我想搜索 id ' childPanel09
'的面板是否是父面板的子面板。
[Possibly without using iteration]
[可能不使用迭代]
Note:I am using ExtJs 3.4
注意:我使用的是 ExtJs 3.4
回答by Molecular Man
If you want to search only among direct childs of parentPanel you can use getComponent:
如果您只想在 parentPanel 的直接子项中搜索,您可以使用getComponent:
var childPanel = Ext.getCmp('parentPanel').getComponent('childPanel09');
if (childPanel) {
alert('yes. child exists');
}
If you want to search not only among direct childs but at any layer under the parentPanel you can use find:
如果您不仅要在直接子项中搜索,还要在 parentPanel 下的任何层搜索,您可以使用find:
var childPanel = Ext.getCmp('parentPanel').find('id', 'childPanel09')[0]; // [0] because find returns array
if (childPanel) {
alert('yes. child exists');
}
回答by Craig Walker
Ext.Container.find()
(from the accepted answer) is fine as of ExtJS 3.4(which is what the question asked about). However, in ExtJS 4.0 and above, find()
was removed in favour of Ext.Container.query(), which accomplishes the same thing.
Ext.Container.find()
(来自接受的答案)从ExtJS 3.4 开始就很好(这是问题所问的问题)。然而,在 ExtJS 4.0 及更高版本中,find()
已被移除,取而代之的是Ext.Container.query(),它完成了同样的事情。