2011-11-14 7 views
0

私はjavascript.Letの私は、次のコードがあるとしでのスコープの理解の問題があります:あなたが見ることができるようにextjsでクラスの祖父母関数を呼び出す方法は?

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 

を、this.editUserは()Ext.Ajax.requestとupdateUser

にネストされている

この.editUser()はundefinedを返します。コールバック内でeditUserを呼び出せますか?

答えて

1

これは単なるスコープの問題です。 updateUserメソッドでスコープがコントローラであるため、コールバック内でeditUserを呼び出すには、スコープをajaxリクエストに追加するだけです。

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 
関連する問題