我有一个主干视图,我想在 2 个异步调用之后呈现 html:
initialize: function (model, options) {
team.fetch({
success: function (collection) {
//do some things
});
goal.fetch({
success: function (collection) {
//do some things
});
this.render();
}
render: function () {
this.$el.html(template());
return this;
}
显然,使用上面的代码,html 模板将在 ajax 调用之前/期间返回。通常,当只有一个 ajax 调用时,我会:
initialize: function (model, options) {
var that = this;
team.fetch({
success: function (collection) {
//do some things
that.render();
});
}
render: function () {
this.$el.html(template());
return this;
}
使用多个 ajax 调用执行此操作的最优雅的方法是什么?