PDA

View Full Version : Easier way to get nested items (Panel)



iamcam
17 Jan 2011, 5:21 PM
There has to be an easier way, but I can't figure it out - what is the right way to get this sort of item?

srch = People.myListPanel.getDockedItems()[1].items.items[0].getValue();

I'm basically trying to get a value of a search box inside of a DockedItem - the field name and id is "searchfield"

Thanks!!
Cameron

gcallaghan
18 Jan 2011, 4:58 PM
Whats the context of trying to get the search? If it is event based, you can often have a reference to the component firing the event. If this doesn't give you direct access to a component it often reduces the depth you have to query.

The other technique I use if I need to reference a nested item frequently is to store a object property that refers to it on initialization: Something like....


MyListPanel = Ext.extend(Ext.Panel,{
initComponent:function(){
MyListPanel.superclass.initComponent.call(this);
searchform = new Ext.form({items:[{xtype:'textfield'}]});
this.search = searchform.items.get(0);
this.addDocked(searchform);
}
});

People.myListPanel = new MyListPanel();
srch = People.myListPanel.search;

anthony-apd
18 Jan 2011, 8:03 PM
If you set an ID on the field, then you could use Ext.getCmp("IDGOESHERE").
If you set an itemId on the field you want, then you could use myPanel.down("ITEMIDGOESHERE") or myPanel.query("ITEMIDGOESHERE").
Any one of those should return the component. Keep in mind that if you use query(), it always returns an array.

iamcam
24 Jan 2011, 11:46 AM
Thanks guys. I'll take a look at those. The search field is there just for an AJAX search request, so I just attach the behavior to the search button.

mitchellsimoens
24 Jan 2011, 1:38 PM
itemId is a much better route than ID

iamcam
24 Jan 2011, 1:56 PM
How would that work? Is it at all like the solution anthony-apd suggested?