无法更改按钮点击变量的值 - Sencha [英] Unable to change the value of variable in button click - Sencha

查看:137
本文介绍了无法更改按钮点击变量的值 - Sencha的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图改变变量的值,并且在

I am trying to change value of variable and i did as instruction in this post but value does not changes.

我的代码如下:


My codes are as follow:

Ext.define('MyApp.view.OnlineOffline', {
extend: 'Ext.Panel',  
alias: "widget.onlineoffline", 

config: {    
onlineStatus: 0,
items: [
{
xtype: 'container',
layout: 'hbox',     
cls: 'offline-wrap',
items:[
{

xtype: 'image',
cls: 'offlineCheck',
id:'onlineButton',      
width: 85,      
height:20,      
listeners: {
tap: function (button) 
{
var me = button.up('onlineoffline')
if (!Ext.device.Connection.isOnline()) 
{
 Ext.Msg.alert('Please connect to <br/>working internet Connection?');
 this.element.removeCls('onlineCheck');
 this.element.addCls('offlineCheck');
 me.setonlineStatus(1);
 } 
 else {
if(me.getOnlineStatus())
{  
console.log( 'connection yes if' + me.getOnlineStatus());                   
me.setOnlineStatus(1);
this.element.removeCls('onlineCheck');
this.element.addCls('offlineCheck');
}
else{
this.element.removeCls('offlineCheck');
this.element.addCls('onlineCheck'); 
me.setOnlineStatus(0);
console.log( 'connection yes else' + me.getOnlineStatus());                                      
} 
}
}
}
},          
]
}]
}
});


推荐答案

这里有几件事...

首先,您将 me 初始化为全局变量,这是一个坏主意。而不是这样做,使用按钮来获取对 me 的引用:

First, you are initializing me as a global variable, which is a bad idea. Rather than doing this, get a reference to what you have as me using the button:

listeners: {
    tap: function (button) {
        var me = button.up('onlineoffline')
        ...

您遇到的问题是由于您调用了错误的函数而引起的。您的 config 参数定义为 onlineStatus ,但是您要调用 setonlinestatus()。改为调用 me.setOnlineStatus()。生成的getter和setter的camel-casing将完全按照你的 config 参数完成,除了第一个字母将被大写。

The problem you are having is caused because you're calling the wrong function. Your config parameter is defined as onlineStatus, but you are calling setonlinestatus(). Call me.setOnlineStatus() instead. The camel-casing for the generated getters and setters will be done exactly as your config param, except the first letter will be capitalized.

这篇关于无法更改按钮点击变量的值 - Sencha的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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