无法访问Sencha中的全局变量整个一个控制器 [英] Unable to access global variable entire one controller in sencha

查看:67
本文介绍了无法访问Sencha中的全局变量整个一个控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图在一个控制器内访问全局值,但是无法访问它.我一直在关注如何在sencha中定义全局变量,但是可以设置并访问全局值.

I have been trying to access global value inside one controller, but could not access it. i have been following this How to define global variable in sencha but could not set and access global values.

在控制器中

config: {
    successMessage:100,
    control: {
      'submitnewword': {
         activate: 'onActivate',
         itemtap: 'onItemTap',
         ConfirmTestCommand:'Confirm'
        },
    .......
   },
  onSearchKeyUp: function(searchField) {
    success: function (response) {
       this.setSuccessMessage(1);
   }
   else {
     this.setSuccessMessage(0);
   }   
}

and access it

Confirm: function () {
   console.log("Confirm----- Caling on Controller");
   var testing=this.getSuccessMessage();
   console.log("Confirm----- value--"+testing);         
},

我不知道,我的代码有什么问题.

I dont know, what is the wrong with my code.

我在控制台上得到了这个

I am getting this on console:

未捕获的TypeError:对象[object global]没有方法 'setSuccessMessage'

Uncaught TypeError: Object [object global] has no method 'setSuccessMessage'

推荐答案

问题与范围有关,您可以通过以下方法解决:

The problem is about scope and you can solve it by:

在控制器的init方法中

In your controller init method

init : function() {
   me = this;
}

现在使用

   me.setSuccessMessage(1)

   me.getSuccessMessage();

这篇关于无法访问Sencha中的全局变量整个一个控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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