I have a property in my controller which I need to change its value in one method and access the updated value in another function. How can I do this?
Ext.define('App.controller.MyController', {
extend: 'Ext.app.Controller',
config:{
Var : 'Test',
},
method1:function(){
var me = this;
var str1 = me.getVar();
//change str1 here to Test2
},
method2:function(){
var me = this;
var str2 = me.getVar();
//get updated value here (Test2)
}
As your property is defined via config
, getter and setter methods are already generated automatically, i.e. in method1
you can just call the setter to change the value:
method1: function() {
var me = this;
me.setVar('Test2');
},
Also refer to the documentation, as this very basic case is covered there.