2014-09-25 50 views
-1

我想調用小部件中的函數SetLoginButtonLabel從函數內部登錄SetLoginInfo - SetLoginInfo是從小部件LogInDB的回調。當我嘗試使用this.SetLoginButtonLabel調用它時,我得到錯誤SetLoginButtonLabel未定義。我也試圖如下所示,但那不工作。我想從SetLoginInfo調用幾個不同的函數 - 我怎樣才能使用hitch或其他方法來完成這項工作?在一個自定義小部件中調用函數是一個回調

感謝

---控件登錄

... 
postCreate: function() { 
var SetLab = lang.hitch(this, "SetLoginButtonLabel"); 

} 

Login: function() //call the database 
{ 

LoginDB.Login("http://xxx/John Smith", this.SetLoginINfo) 
}, 


SetLoginInfo: function(LoginData) //call back from LoginDB 
{ 
//I've tried: 
this.SetLogingButtonLabel("status"); //get an undefined error 

//and 
SetLab("Logout");//this just seems to get lost 

}, 

SetLoginButtonLabel: function(status) 
{ 
// 
} 

....... 

---小部件LoginDB

define(['dojo/store/Memory', 'dojo/_base/xhr', "dojo/data/ObjectStore", 'dojo/_base/json'], 
//functions to get data and fill data stores 
function (Memory, xhr, ObjectStore) { 
    var TicketStore; 
    return { 
     //login 
     Login: function (url, callback) { 
      xhr.get({//send data 
       url: url, 
       handleAs: "json", 
       load: function (result) { 
        var LoginData = result; 
        callback(LoginData); 

       }, 
       error: function (err) { } 

      }); 
     } 



    } 

}); 
+0

我也嘗試調用DB小部件是這樣的: LoginDB.Login(S,lang.hitch(this.SetTOC)); 仍然得到未定義的錯誤 – pvitt 2014-09-25 23:22:59

+0

而是它是這樣的: LoginDB.Login(s,lang.hitch(this,SetTOC)); – pvitt 2014-09-25 23:30:38

+0

這是行不通的: LoginDB.Login(s,this.SetLoginInfo,lang.hitch(this,this.SetLoginButtonLabel)); 但是我想從setLoginIfo調用一堆函數 – pvitt 2014-09-29 16:43:01

回答

0

,這使得它的工作:

LoginDB.Login(s, lang.hitch(this, this.SetLoginInfo)); 

我的電話的所有內SetLoginInfo我把這個放在了正面:

this.SetLoginButtonLabel("Logged In"); 
相關問題