Javascript 如何在 ExtJS 4 中获取子元素
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6743495/
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 get child element in ExtJS 4
提问by Kunal
How to get all the child elements or id of a Panel in ExtJS 4?
如何在 ExtJS 4 中获取 Panel 的所有子元素或 id?
回答by Zango
I wrote that function for you. I think it will help you.
我为你写了那个函数。我想它会帮助你。
function getAllChildren (panel) {
/*Get children of passed panel or an empty array if it doesn't have thems.*/
var children = panel.items ? panel.items.items : [];
/*For each child get their children and concatenate to result.*/
Ext.each(children, function (child) {
children = children.concat(getAllChildren(child));
})
return children;
}
它将面板(容器)作为参数并递归返回所有子级和子级。 EDITThis will return ids of children. USES PREVIOUS FUNCTION - getAllChilden
编辑这将返回儿童的 ID。使用以前的功能 - getAllChilden
function getAllChildenIds(panel) {
//*Get all child items. \*/
var children = getAllChilden(panel);
//*Replace items with their ids.\*/
for (var i=0, l=children.length; i < l; i++) {
children[i] = children[i].getId();
}
return children;
}
回答by user463226
Just call query() on your panel which will return an array of all child elements which match an optional selector. i.e. panel.query()
只需在面板上调用 query() ,它将返回与可选选择器匹配的所有子元素的数组。即 panel.query()