-
30 Jun 2010 10:23 AM #1
getCard not available from tab activate listener
getCard not available from tab activate listener
First alert says 'C1', second alert says 'undefined'
Code:Ext.setup({ onReady: function () { new Ext.TabPanel({ fullscreen: true, items: [{ title: 'I1' }, { title: 'I2', card: 'C1', listeners: { activate: function () { alert(this.card); alert(this.getCard); } }}] }); } });
-
30 Jun 2010 10:46 AM #2Sencha - Sencha Touch Dev Team
- Join Date
- Mar 2007
- Location
- Haarlem, Netherlands
- Posts
- 1,235
- Vote Rating
- 4
We don't have a property (nor a method if you would add parentheses) called getCard and don't see a definition.
You could do the following.
Code:Ext.setup({ onReady: function () { new Ext.TabPanel({ fullscreen: true, items: [{ title: 'I1' }, { title: 'I2', card: 'C1', getCard: function() { return this.card; }, listeners: { activate: function () { alert(this.card); alert(this.getCard()); } } }] }); } });
-
30 Jun 2010 11:04 AM #3
Note: card is not listed as a public property in the Tab documentation.
The reason I was expecting getCard to be there:
If you click on Ext.Tab in the documentation to see the source (http://www.sencha.com/deploy/touch/d...ml#cls-Ext.Tab) you can see the following:
/**
* Retrieves a reference to the card associated with this tab
* @returns {Mixed} card
*/
getCard : function() {
return this.card;
},
-
30 Jun 2010 11:12 AM #4Sencha - Sencha Touch Dev Team
- Join Date
- Mar 2007
- Location
- Haarlem, Netherlands
- Posts
- 1,235
- Vote Rating
- 4
Ah, only now I see what you were trying to do. I never really thought about the fact that people would want to change the card associated to a tab. Thus the fact that it is private and not documented.
Anyway, the reason this.setCard is not defined is because of the scope that the activate handler runs in by default. "this" inside your handler refers to the card, not the tab.
Try applying the following patch (which will probably be part of the next release)
then you should be able to do the following in your event handler.Code:Ext.override(Ext.TabBar, { // @private onCardAdd : function(panel, card) { card.tab = this.add({ xtype: 'tab', card: card }); }, // @private onCardRemove : function(panel, card) { var items = this.items.items, ln = items.length, i, item; for (i = 0; i < ln; i++) { item = items[i]; if (item.card === card) { item.card = null; this.remove(item, true); return; } } } });
Code:this.tab.setCard(...);
-
30 Jun 2010 11:18 AM #5
Actually I pasted in setCard by mistake
I am using getCard because I'm simulating the twitter example, but instead of referencing the twitter panel as a variable, I add the following to my tab panel:
{ iconCls: 'chat', card: new twitter.TimeLine(), title: 'Twitter', listeners: { activate: function () { this.card.store.read(); } }}
I first tried this.getCard() based on the documentation script, but it didn't work. Thanks for the workaround
-
30 Jun 2010 11:19 AM #6Sencha - Sencha Touch Dev Team
- Join Date
- Mar 2007
- Location
- Haarlem, Netherlands
- Posts
- 1,235
- Vote Rating
- 4
In that case you don't need to apply my patch with that override. Like I mentioned before, the default scope of the activate event is the card itself.
In your case you could just do this.store.read();
-
30 Jun 2010 11:24 AM #7
Now I get why I was confused... the Tab documentation read:
activate : ( Ext.Tab this )
Listeners will be called with the following arguments:- this : Ext.Tab

-
30 Jun 2010 11:31 AM #8Sencha - Sencha Touch Dev Team
- Join Date
- Mar 2007
- Location
- Haarlem, Netherlands
- Posts
- 1,235
- Vote Rating
- 4
Totally agree.
At least we are all on the same page now.
Thank you for reporting this bug. We will make it our priority to review this report.
Similar Threads
-
Tabs activate listener - odd behavior
By str2etboy in forum Ext 2.x: Help & DiscussionReplies: 1Last Post: 20 Jun 2008, 9:53 AM -
how to get tab panel title from activate listener
By vik in forum Ext 2.x: Help & DiscussionReplies: 7Last Post: 29 May 2008, 9:58 AM -
How to activate a tab
By leewu in forum Ext 2.x: Help & DiscussionReplies: 3Last Post: 11 Feb 2008, 5:17 PM -
How to activate a tab with only ID's?
By aaronshaf in forum Ext 2.x: Help & DiscussionReplies: 3Last Post: 4 Nov 2007, 10:01 AM -
can i set 'activate' tab or 'disable' tab with dialog's 'autoTabs'?
By perthkit in forum Ext 1.x: Help & DiscussionReplies: 1Last Post: 26 Jul 2007, 10:11 PM


Reply With Quote
