我是新來moootools和我創建一個模板類,這是我的代碼 -如何確定在mootools中完成請求的時間?
var Template = new Class({
Singleton : true,
template : '',
/* gets the component type template */
get : function(componentType){
var tplUrl = Core.getUrl('backend') + 'response/' + componentType + '/get_template.php',
that = this,
request = new Request({url: tplUrl, method : 'get',onSuccess : function(responseText){
that.template = responseText;
return that;
}}).send();
}
});
我想要做的是這樣的:
var tpl = new Template();
tpl.get('component').setTemplateData({name:'yosy'});
問題是,當我打電話這代碼:
var tpl = new Template();
console.log(tpl.get('component'));
我沒有得到我當前的Template對象,我得到的是'undefined'。
我如何使這個可鏈接?
爲了使它可鏈接,他也可以變成一個同步請求,雖然它擊敗了目的:) – 2010-08-24 16:34:10
我已經停止推薦同步選項:)但好的替代品將是[期貨和承諾]的這個概念(http:///en.wikipedia.org/wiki/Futures_and_promises)以及Dustin Diaz的[async method queues](http://www.dustindiaz.com/async-method-queues/)。 – Anurag 2010-08-24 16:51:45