在我的骨幹應用程序中加載3個集合,並在渲染函數中綁定「重置」事件。所以,通過這種方式,當我獲取集合時,我會打印各種結果,但不會同時打印。骨幹,在全部加載時觸發事件
我會使用jquery延遲方法($ .when,$ .then)同時打印所有,如何在視圖上使用「綁定事件」來執行此操作?
這是代碼:
路由器:
App.Routers.test1 = Backbone.Router.extend({
routes: {
"/test" : "test"
},
initialize: function() {
// Models
this.Models_1 = new App.Collections.coll_1;
this.Models_2 = new App.Collections.coll_2;
this.Models_3 = new App.Collections.coll_3;
// Views
this.View_1 = new App.Views.view_1({model: this.Models_1});
this.View_2 = new App.Views.view_2({model: this.Models_2});
this.View_3 = new App.Views.view_3({model: this.Models_3});
},
test: function() {
$.when(
this.Models_1.fetch(),
this.Models_2.fetch(),
this.Models_3.fetch()
).then(function() {
// ?????????????????????????
// What should I do here?
// ?????????????????????????
});
}
});
視圖1:
App.Views.view_1 = Backbone.View.extend({
initialize: function() {
_.bindAll(this, 'render');
this.model.bind('reset', this.render);
},
render: function() {
// print the data...
}
});
在「then」功能中,「this」不起作用。怎麼做? – keepyourweb
將綁定範圍的代碼更新爲'then'函數 –