-->

如何定义在煎茶全局变量(How to define global variable in sench

2019-10-18 10:45发布

我尝试全局变量在一个完整的视图,也没有这样做。

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);
}

但我不能访问它,它总是显示为0。我已经给了输入RAM,那么它也给我0.why这一点。 全局变量不能正常工作。

Answer 1:

你可以这样使用自动设置器/吸气:

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() );
}


文章来源: How to define global variable in sencha