0
我試圖在我的代碼的其他部分觸發「page:change:after」事件時重新呈現一個Marionette ItemView。我試圖做它在兩個方面:Backbone marionette render
1.
self.listenTo(this.paginatedCollection,"page:change:after",function(){
console.log("page:change:after detected!!!!!!!!!!!!!!!!!!");
self.render;
});
2.
this.listenTo(this.paginatedCollection,"page:change:after",self.render);
出於某種原因,#2的作品,但不是#1。控制檯登錄#1的回調確實運行(我可以在控制檯上看到「頁面:更改:檢測到後」)。我還添加了一個打印出「onRender!」的onRender方法當我使用#2,但不是#1。它看起來像是沒有用#1渲染。有人能提供一些有關這種行爲的見解嗎?
下面是一個更完整的代碼片段,以提供更好的情境:
Views.PaginationControls = Marionette.ItemView.extend({
template: "#contact-paginator",
initialize: function(options){
var self = this;
this.paginatedCollection = options.paginatedCollection;
//why is this not working?
self.listenTo(this.paginatedCollection,"page:change:after",function(){
console.log("page:change:after detected!!!!!!!!!!!!!!!!!!");
self.render;
});
//this works
this.listenTo(this.paginatedCollection,"page:change:after",self.render);
},
onRender: function(){
console.log("onRender!")
}
});
是的,你:我認爲這會工作,可能是清潔的,因爲你可以得到完全擺脫自我的 - 問題
那說的是絕對正確的。我怎麼能看不到!謝謝。 – nsxtasy 2014-09-03 20:22:33