user2988855
user2988855

Reputation: 296

setactiveitem works only once

my problem is i have 3 view files and one controller.

the following is the code for 3 button tap events.

onb1:function(){

    Ext.Viewport.remove(Ext.Viewport.getActiveItem(), true);

    Ext.Viewport.add({xtype:'second',height:'30%',style:'background:red'}).show();

},

onb3:function(){

    Ext.Viewport.remove(Ext.Viewport.getActiveItem(), true);

    Ext.Viewport.add({xtype:'main'}).show();

},

onb2:function(){

    Ext.Viewport.remove(Ext.Viewport.getActiveItem(), true);

    Ext.Viewport.add({xtype:'third',height:'60%',style:'background:orange'}).show();

}

it works only once.

tell me any solution...

Upvotes: 1

Views: 455

Answers (2)

Thiem Nguyen
Thiem Nguyen

Reputation: 6365

The reason is, this line of code:

Ext.Viewport.remove(Ext.Viewport.getActiveItem(), true);

will remove your component, then destroy it.

Perhaps you must have defined your handlers in a way that they are binded to these components only on definition, not initialization.

So, if you do not declare the handler function in the initialize method of the components which you add/remove frequently.

Says your components are buttons, so your definition files should look like this:

Ext.define('mybutton',{
    extend: 'Ext.Button',
    config: {
        text: 'my button'
    },
    initialize: function(){
        var me = this;
        this.addListener({
            fn: me.doSmt,
            event: 'tap'
        });
    }
    doSmt: function(){
        // implement your logics here.......
    }
});

Upvotes: 1

Christian Orth
Christian Orth

Reputation: 4673

The activeItem is automatically set the first time. After that you have to set it yourself. There is also no need to call show(). Should work like this:

    Ext.Viewport.add(someView);     
    Ext.Viewport.setActiveItem(someView);

Upvotes: 1

Related Questions