2

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.

in Controller

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:

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

Cœur
  • 37,241
  • 25
  • 195
  • 267

3 Answers3

1

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

In your controller init method

init : function() {
   me = this;
}

Now access the methods using

   me.setSuccessMessage(1)

   me.getSuccessMessage();
Viswa
  • 3,211
  • 5
  • 34
  • 65
0

I think you ran onto the scope visibility issue... I'm not sure where an exception is emitted, from onSearchKeyUp() or from Confirm(). But guess inside it this points not to the controller instance. To help you more you need share more info (sources)

olegtaranenko
  • 3,722
  • 3
  • 26
  • 33
0

The success function inside onSearchKeyUp has a different scope when it is called. So, inside it, this is not your controller where the successMessage (and of course, its getter and setter) is defined.

A solution is to "bind" the success function to the controller scope using:

success: Ext.bind(function (response) {
       this.setSuccessMessage(1);
}, this);
Claudio Bertozzi
  • 536
  • 4
  • 12