How to define global variable in sencha

一笑奈何 提交于 2020-01-05 09:21:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!