Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在ExtJS4中获取子元素_Javascript_Extjs_Extjs4 - Fatal编程技术网

Javascript 如何在ExtJS4中获取子元素

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

如何在ExtJS 4中获取面板的所有子元素或id?

我为您编写了该函数。我想这会对你有帮助。

函数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;i只需在面板上调用query(),它将返回与可选选择器匹配的所有子元素的数组。
i、 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;
}