问题
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.
回答1:
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() );
}
来源:https://stackoverflow.com/questions/18095037/how-to-define-global-variable-in-sencha