如何在ExtJS 4中获取子元素

Kun*_*nal 7 javascript extjs extjs4

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

Zan*_*ngo 15

我为你写了这个功能.我认为它会对你有所帮助.

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;
}
Run Code Online (Sandbox Code Playgroud) 它将面板(容器)作为参数,并递归返回所有子项和子项.

编辑 这将返回儿童的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;
}
Run Code Online (Sandbox Code Playgroud)


小智 10

只需在面板上调用query(),它将返回与可选选择器匹配的所有子元素的数组.ie panel.query()