Reputation: 4059
I have issues understanding scopes in javascript.Let's suppose i have the following code:
Ext.define('MA.controller.user',{
extend : 'Ext.app.Controller',
editUser:function(){},
updateUser : function() {
Ext.Ajax.request({
url : './editall',
callback : function(options, success, response) {
this.editUser();
}
})
}//eof init
})//eof class
As you can see, this.editUser() is nested into Ext.Ajax.request and updateUser
this.editUser() will return undefined.How can i call editUser inside callback?
Upvotes: 0
Views: 857
Reputation: 4493
It's just a scope issue. In the updateUser method the scope is the controller,so to call the editUser inside the callback just add the scope to the ajax request
Ext.define('MA.controller.user',{
extend : 'Ext.app.Controller',
editUser:function(){},
updateUser : function() {
//here this refers to the controller
Ext.Ajax.request({
url : './editall',
scope: this, // add the scope as the controller
callback : function(options, success, response) {
this.editUser();
}
})
}//eof init
})//eof class
Upvotes: 1