Javascript 如何在ExtJS4中获取子元素
如何在ExtJS 4中获取面板的所有子元素或id?我为您编写了该函数。我想这会对你有帮助。Javascript 如何在ExtJS4中获取子元素,javascript,extjs,extjs4,Javascript,Extjs,Extjs4,如何在ExtJS 4中获取面板的所有子元素或id?我为您编写了该函数。我想这会对你有帮助。 函数getAllChildren(面板){ /*获取传递的面板或空数组(如果没有)的子级*/ var children=panel.items?panel.items.items:[]; /*对于每个子对象,获取其子对象并连接到结果*/ Ext.each(子项,函数(子项){ children=children.concat(getAllChildren(child)); }) 返回儿童; } 它将p
函数getAllChildren(面板){
/*获取传递的面板或空数组(如果没有)的子级*/
var children=panel.items?panel.items.items:[];
/*对于每个子对象,获取其子对象并连接到结果*/
Ext.each(子项,函数(子项){
children=children.concat(getAllChildren(child));
})
返回儿童;
}
它将panel(container)作为参数,并递归返回所有子级和子级
编辑
这将返回孩子的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;
}
函数GetAllChildenId(面板){
//*获取所有子项\*/
var children=getAllChilden(面板);
//*将项目替换为其ID\*/
for(变量i=0,l=children.length;ii、 e.panel.query()谢谢Zango,您的代码运行良好,但我需要panel的每个子元素的id。但面对这个问题。
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;
}