0

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());                                      
} 
}
}
}
},          
]
}]
}
});
Community
  • 1
  • 1
surhidamatya
  • 2,419
  • 32
  • 56

1 Answers1

1

A couple things here...

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')
        ...

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.

kevhender
  • 4,285
  • 1
  • 13
  • 16
  • I did as you said but value does not changes. in button tap condition only goes to else not to if. – surhidamatya Aug 27 '13 at 11:51
  • In your `if` statement, you still need to use `me.getOnlineStatus()`, as `me.onlineStatus` will not work. – kevhender Aug 27 '13 at 11:52
  • done but no change in value. It consoles connection yes else0 – surhidamatya Aug 27 '13 at 11:56
  • 1
    What do you mean it does not change? Your initial `config` sets `onlineStatus` to `0`, so it will hit the `else` statement. Then, you are doing `me.setOnlineStatus(0);` right before that console statement and it is printing 0, the value that you set right before it. Are you meaning to change it to `1` there? – kevhender Aug 27 '13 at 12:01
  • I mean at first the value is 0, when button clicks it should be 1 and vice versa. Yeah your help made me learn new thing today. – surhidamatya Aug 27 '13 at 12:06
  • how can change the value to one as you said. – surhidamatya Aug 28 '13 at 03:30