PDA

View Full Version : how to use the setActiveItem method of Cardlayout??????



bluefox617
5 Feb 2011, 8:27 AM
Here is my code:


App.View.Test = Ext.extend(Ext.Panel,{

layout:'card',
fullscreen:true,
activeItem:0,
initComponent: function() {
Ext.apply(this,{
items:[
{
xtype:'button',
handler:this.ttt
},
{
html:'111'
},
{
html:'222'
}

]

});
App.View.Test.superclass.initComponent.call(this);
},

ttt:function(){
this.setActiveItem(2,'fade');

}

});

It doesn't work,

console said that"TypeError: Object [object Object] has no method 'setActiveItem'"

why?????please help me !!!

mfruhling
5 Feb 2011, 8:59 AM
bluefox617,

The scope of "this" is your button and not your panel. To correct that, setup your button in the items array like this:

{
xtype:'button',
handler:this.ttt,
scope: this
}

That way you'll be passing in the scope of the panel, and within your handler "this" will refer to the panel and not the button. If you ever need access to the button, create the handler function like this:

function ttt(b,e){
// Code here
}

"b" will be your button that called the handler and "e" will be an event object.