-
13 Aug 2012 1:35 AM #1
Answered: Accessing instance of view created with Ext.Define
Answered: Accessing instance of view created with Ext.Define
Looking at the following code
How can I access the instance of this created panel ?Code:var mainpanel = Ext.define("App.view.Main", { extend: 'Ext.tab.Panel', xtype: 'mainpanel', id: 'mainpanel', config: { fullscreen: true, tabBarPosition: 'left', items: [ { xtype: 'homepanel' }, { xtype: 'settingspanel' } ] } });
-
Best Answer Posted by mrsunshine
With the component query
http://docs.sencha.com/touch/2-0/#!/...ComponentQuery
Ext.ComponentQuery.query('homepanel');
-
13 Aug 2012 7:54 AM #2Sencha - Training Team
- Join Date
- Sep 2008
- Location
- Germany - Darmstadt
- Posts
- 682
- Vote Rating
- 10
- Answers
- 21
With the component query
http://docs.sencha.com/touch/2-0/#!/...ComponentQuery
Ext.ComponentQuery.query('homepanel');trainings / workshops / consulting: Sencha Touch / Ext JS
Profile on SenchaDevs
www: http://www.nils-dehl.de
twitter: nilsdehl
meetup: Sencha Touch / Ext JS Meetup Frankfurt
videos: http://vimeo.com/album/1621422
conference photos: http://www.flickr.com/photos/nils-dehl/
-
15 Aug 2012 12:57 AM #3
Thanks
Thanks
Hi
Thanks for the reply. That does indeed work (somewhat) and it caught me out when trying to access 'homepanel'. Here is how I refined it:
-- Ext.ComponentQuery.query('homepanel'); - this returns an array of all components with the xtype 'homepanel' even if there is only one. Trying to access this directly won't work
-- Ext.ComponentQuery.query('homepanel')[0]; - this will access the actual 'homepanel' component directly, which is exactly what I needed.
Another pitfall that caught me. When the function animateActiveItem() is called in the following way:
It creates another instance of the homepanel, so each time the above function is called (from a controller for example) it clones the homepanel. The correct way to do this would be as follows:Code:this.getMain().animateActiveItem( { xtype: 'homepanel' }, { type: 'fade' });
Code:this.getMain().animateActiveItem(Ext.ComponentQuery.query('homepanel')[0], {type: 'fade'});
Hope this helps others who run into this problem in the future.
Thanks again,
Matt


Reply With Quote