Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get child element in ExtJS 4

How to get all the child elements or id of a Panel in ExtJS 4?

like image 297
Kunal Avatar asked Jul 19 '11 07:07

Kunal


Video Answer


1 Answers

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;
}
It takes panel (container) as a parameter and returns all children and subchildren recursively.

EDIT This will return ids of children. USES PREVIOUS FUNCTION - 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;
}
like image 112
Zango Avatar answered Sep 24 '22 23:09

Zango