Sencha touch 如何在sencha中定义全局变量
我试图把全局变量放在一个完整的视图中,但做不到Sencha touch 如何在sencha中定义全局变量,sencha-touch,sencha-touch-2,sencha-touch-2.1,Sencha Touch,Sencha Touch 2,Sencha Touch 2.1,我试图把全局变量放在一个完整的视图中,但做不到 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); }
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);
}
}
访问值窗体按钮点击如下:
onSubmitButtonTap: function () {
console.log("Button Tap Here");
console.log("Test Def-6-"+this.nameValue);
}
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() );
}
但我无法访问它,它始终显示为0。我给了输入ram,然后它也给了我0。为什么会这样。全局变量无法正常工作。您可以像这样使用自动设置器/获取器:
onSubmitButtonTap: function () {
console.log("Button Tap Here");
console.log("Test Def-6-"+this.nameValue);
}
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() );
}
你能告诉我一些关于这个问题的想法吗:@Nico Grunfeld你能看看这个吗