ESV*_*ESV 4 javascript jquery zendesk
在我的ZenDesk应用程序中,我:
使用普通的jQuery,你可以使用jQuery.when(deferreds)协调它,一旦步骤2中的所有请求完成,就触发第3步:
$.when($.ajax("/page1"), $.ajax("/page2"))
.done(function(page1result, page2result) {
// modify the ticket with the results
});
Run Code Online (Sandbox Code Playgroud)
this.$.when()
没有运气.)jQuery.when()
可以通过应用程序对象获得this.when()
.这是一个简单的例子(框架版本0.5),它创建了几个简单的承诺(使用this.promise()
,类似jQuery.Deferred()
)然后等待,直到它们成功/解析为调用第三个函数.
替代this.ajax(...)
的this.createPromise()
做实事.
(function() {
return {
onActivate: function() {
var promises = []
promises.push(this.createPromise().done(function() {
console.log('promise 1 done');
}));
promises.push(this.createPromise().done(function() {
console.log('promise 2 done');
}));
this.when.apply(this, promises).done(function() {
console.log('all promises done');
});
},
// returns a promise that always succeeds after 1 sec.
createPromise: function() {
return this.promise(function(done, fail) {
setTimeout(done, 1000);
});
},
events: {
'app.activated': 'onActivate'
}
};
}());
Run Code Online (Sandbox Code Playgroud)