0
votes

I have a Sencha Touch application I am trying to set a global variable for. EDIT: More clarification, I need to be able to access this global variable across all views.

I set the variable on the application to it's default value, then overwrite it during a launch. However, it's not being overwritten.

Ext.application({
    name: 'hd',
    isAuth: 'false',
    launch: function() {
       hd.app.isAuth = 'true';
       Ext.Msg.alert(hd.app.isAuth); //This always returns 'false'
    }
});

I'm not getting any console errors and I cannot find anyone who is having a similar issue. I'm obviously doing it wrong. Can anyone show me the correct way to do this?

2

2 Answers

1
votes

I think app should not be present here. This code snippet alerts true:

Ext.application({
    name: 'hd',
    isAuth: 'false',
    launch: function() {
       hd.isAuth = 'true';
       Ext.Msg.alert(hd.isAuth); // will return true as I have tested
    }
});

Good luck.

Edited: This should change hd.app.isAuth to your desire value

Ext.application({
    name: 'hd',
    isAuth: 'false',
    setIsAuth: function(value){
        this.isAuth = value;
    },
    launch: function() {
       hd.app.setIsAuth('true');
       Ext.Msg.alert(hd.app.isAuth);
    }
});
0
votes

You can do below

Ext.application({
name: 'hd',
launch: function() {
   this.isAuth = 'true';
   Ext.Msg.alert(hd.isAuth); //This returns 'true'
   this.isAuth = 'false';
   Ext.Msg.alert(hd.isAuth);//This returns 'false';
}});