Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to search for a child in a panel in ExtJs

How can I find if a particular child (item) exists in a panel using the id of the child.

Say I have a parent paned (id = parentPanel) and few panels as items of this parent panel. Now, I would like to search if a panel by id 'childPanel09' is a child of parent panel.

[Possibly without using iteration]

Note: I am using ExtJs 3.4

like image 701
hop Avatar asked Feb 06 '12 10:02

hop


2 Answers

If you want to search only among direct childs of parentPanel you can use getComponent:

var childPanel = Ext.getCmp('parentPanel').getComponent('childPanel09');
if (childPanel) {
  alert('yes. child exists');
}

If you want to search not only among direct childs but at any layer under the parentPanel you can use find:

var childPanel = Ext.getCmp('parentPanel').find('id', 'childPanel09')[0]; // [0] because find returns array
if (childPanel) {
  alert('yes. child exists');
}
like image 173
Molecular Man Avatar answered Nov 04 '22 18:11

Molecular Man


Ext.Container.find() (from the accepted answer) is fine as of ExtJS 3.4 (which is what the question asked about). However, in ExtJS 4.0 and above, find() was removed in favour of Ext.Container.query(), which accomplishes the same thing.

like image 2
Craig Walker Avatar answered Nov 04 '22 16:11

Craig Walker