Search code examples
sencha-touch-2sencha-architect

Ext.Msg.confirm - Object [object Window] has no method '...'


I am trying to set up a confirmation message on push of a logout button, where if the users clicks 'yes' then is redirected to panel control in a container called 'myContainer'. The message appears fine but when I select 'yes' I get an error (assuming because the container is not initialized). I have a reference set up on my controller to the container, but that does not seem to help. Any advise on how to handle confirmation correctly like this is appreciated. Thanks

Confirmation message:

onLogoutTap: function(button, e, options) {
Ext.Msg.confirm("Logout", "Do you wish to continue?", function(button){
    if (button == 'yes') {
    //doesn't work:
        this.getMyContainer().setActiveItem(1);
    } else {
        return false;
    }
});
}

myContainer reference in Controller

myContainer: '#myContainer'

Error message:

Uncaught TypeError: Object [object Window] has no method 'getMyContainer'

Solution

  • A little trick I often use is this

    onLogoutTap: function(button, e, options) {
      var controller = this;
      Ext.Msg.confirm("Logout", "Do you wish to continue?", function (button) {
        if (button == 'yes') {
        //doesn't work:
            controller.getMyContainer().setActiveItem(1);
        } else {
            return false;
        }
      });
    }
    

    Like so, you can still access the function object with the keyword this.

    Hope this helps