- var def = new dojo.Deferred(),
- userlist = dojo.byId("userlist");
- def.then(function(res){
- // This will be called when the deferred
- // is resolved
- dojo.forEach(res, function(user){
- dojo.create("li", {
- id: user.id,
- innerHTML: user.username + ": " + user.name
- }, userlist);
- });
- },function(err){
- // This will be called when the deferred
- // is rejected
- dojo.create("li", {
- innerHTML: "Error: " + err
- }, userlist);
- });
- dojo.xhrGet({
- url: "users.json",
- handleAs: "json",
- load: function(res){
- // Resolve when content is received
- def.resolve(res);
- },
- error: function(err){
- // Reject on error
- def.reject(err);
- }
- });
def.then的用法
最新推荐文章于 2023-12-12 11:44:47 发布