如何在SERCHA中定义全局变量 [英] How to define global variable in sencha

查看:13
本文介绍了如何在SERCHA中定义全局变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在一个完整的视图中全局变量,但未能成功。

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。为什么这样。全局变量无法正常工作。

推荐答案

您可以这样使用自动设置/获取方法:

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

这篇关于如何在SERCHA中定义全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆