バックボーン ビューがあり、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 呼び出しが 1 つだけの場合は、次のようにします。
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 呼び出しでこれを行うための最もエレガントな方法は何ですか?