Dojo 推迟道场
从小部件中的方法获取延迟返回时,我遇到了一点问题。方法本身返回一个Deferred,因为它是xhrPost。代码是这样的(使用Dojo1.8) 呼叫代码:Dojo 推迟道场,dojo,widget,deferred,Dojo,Widget,Deferred,从小部件中的方法获取延迟返回时,我遇到了一点问题。方法本身返回一个Deferred,因为它是xhrPost。代码是这样的(使用Dojo1.8) 呼叫代码: quorum = registry.byId("quorumPanel"); var deferredResponse = quorum.updateSelectionCount(); deferredResponse.then(function(data){ console.log("Success: ", data); },
quorum = registry.byId("quorumPanel");
var deferredResponse = quorum.updateSelectionCount();
deferredResponse.then(function(data){
console.log("Success: ", data);
}, function(err){
console.log("Error: ", err);
});
以及小部件中的代码:
updateSelectionCount: function() {
var self = this;
var deferredResponse = xhr.post({
url: "ajxclwrp.php",
content: [arguments here],
handleAs: "json"});
deferredResponse.then(function(response) {
var anotherDeferred = new Deferred();
var _boolA = true;
var _boolB = true;
dojo.forEach(response.result, function(relationshipInfo){
[do a bunch of stuff here too set _boolA and/or _boolB]
});
self._sethasRequiredAttr(_hasRequired);
self._setHasRequestedAttr(_hasRequested);
self.quorumInfo.innerHTML = quorumHtml;
// Below is not working
anotherDeferred.resolve('foo');
return anotherDeferred;
});
}
我是否需要建立另一个承诺并使用承诺/全部。在这一点上我感到困惑/沮丧
TIA.the.then()方法返回另一个延迟。你只需要在里面放一个return语句
updateSelectionCount: function() {
var self = this;
var deferredResponse = xhr.post({
url: "ajxclwrp.php",
content: [arguments here],
handleAs: "json"});
return deferredResponse.then(function(response) {
var _boolA = true;
var _boolB = true;
dojo.forEach(response.result, function(relationshipInfo){
[do a bunch of stuff here too set _boolA and/or _boolB]
});
self._sethasRequiredAttr(_hasRequired);
self._setHasRequestedAttr(_hasRequested);
self.quorumInfo.innerHTML = quorumHtml;
return "foo";
});
}