user1391869
user1391869

Reputation:

How to define global variable in sencha

I am try to global variable in one entire view, could not done it.

initialize : function(){
    this.callParent();

    this.nameValue=0;
if(name="ram")
    this.nameValue=1;
     console.log("Test 1 -"+this.nameValue);
}else {
 this.nameValue=0;
     console.log("Test 2 -"+this.nameValue);
}

}

it would be access value form button tap like this:

onSubmitButtonTap: function () {
 console.log("Button Tap Here");
 console.log("Test Def-6-"+this.nameValue);
}

But i could not access it, it display always 0. I have gave input ram, then it also give me 0.why this. global variable could not works fine.

Upvotes: 1

Views: 1868

Answers (1)

Nico Grunfeld
Nico Grunfeld

Reputation: 1133

You can use the auto setters/getters like this:

config: {
    nameValue: 0,

    listeners: {
        initialize : function() {
            if (name="ram") {
                this.setNameValue(1);
                console.log("Test 1 -" + this.getNameValue() );
            } else {
                this.setNameValue(0);
                console.log("Test 2 -" + this.getNameValue() );
            }
        }
    }
},

onSubmitButtonTap: function () {
    console.log("Button Tap Here");
    console.log("Test Def-6-" + this.getNameValue() );
}

Upvotes: 2

Related Questions