-
9 Oct 2012 8:47 PM #1
Unanswered: Question on referencing objects inside of a view
Unanswered: Question on referencing objects inside of a view
I'm new to Sencha (using 4.1.1), so this is probably a very basic quesion. In the code example below, why is a a reference to the panel, and b undefined? Is there a different method I need to use to reference a nested object?
Thanks,Code:Ext.define('SFC.view.flashcard.Show' ,{ extend: 'Ext.container.Container', alias : 'widget.flashcardshow', layout: 'fit', title : 'Flashcard TODO', store: 'SpanishWords', items : [ { itemId: 'flashWord', xtype: 'panel', layout: 'hbox', title: 'Spanish Flashcards', items: [ { xtype: 'text', itemId: 'foobar', text: 'palabra' } ] } ], initComponent: function() { this.callParent(arguments); }, updateWord: function(newWord) { // THIS WORKS: var a = this.getComponent("flashWord"); console.log(a); // THIS DOES NOT: var b = this.ownerCt.getComponent("foobar"); console.log(b); } });
Antun
-
9 Oct 2012 8:49 PM #2Sencha - Ext JS Dev Team
- Join Date
- Apr 2007
- Location
- Sydney, Australia
- Posts
- 15,105
- Vote Rating
- 97
- Answers
- 171
this refers to
getComponent gets a direct child by id, so that's why a works.Code:SFC.view.flashcard.Show
In the second case, you're asking for the parent of
Then trying to get a single child component with an id of foobar, which, obviously, doesn't exist.Code:SFC.view.flashcard.Show
If you did:
It should work.Code:var b = a.getComponent("foobar");Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
10 Oct 2012 6:41 AM #3
Thank you for the explanation. It works for me now. I ended up doing:
this.getComponent("flashWord").getComponent("foobar");
Is there a way to get around having to step through the hierarchy? e.g. an equivalent of getElementById?
Thanks,
Antun


Reply With Quote