Backbone.js 主干木偶渲染器
当从代码的其他部分触发page:change:after事件时,我试图重新呈现木偶项视图。我尝试了两种方法: 一, 二, 出于某种原因,2可以工作,但不是1。虽然我可以在控制台上看到page:change:after,但1的回调中的控制台日志确实运行了。我还添加了一个onRender方法,可以输出onRender!当我使用2,但不是1时。看起来视图没有使用1进行渲染。有人能提供一些关于这种行为的见解吗 下面是一个更完整的代码片段,可以提供更好的上下文:Backbone.js 主干木偶渲染器,backbone.js,rendering,marionette,backbone-views,backbone-events,Backbone.js,Rendering,Marionette,Backbone Views,Backbone Events,当从代码的其他部分触发page:change:after事件时,我试图重新呈现木偶项视图。我尝试了两种方法: 一, 二, 出于某种原因,2可以工作,但不是1。虽然我可以在控制台上看到page:change:after,但1的回调中的控制台日志确实运行了。我还添加了一个onRender方法,可以输出onRender!当我使用2,但不是1时。看起来视图没有使用1进行渲染。有人能提供一些关于这种行为的见解吗 下面是一个更完整的代码片段,可以提供更好的上下文: Views.PaginationContr
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!")
}
});
在第一个示例中,您没有执行该方法-应该是“self.render”-我怀疑这是问题的根源 也就是说,我认为这会起作用,而且可能更干净,因为你可以完全摆脱自我:
this.listenTothis.paginatedCollection,page:change:after,this.render 是的,你完全正确。我怎么能看不到呢!非常感谢。
this.listenTo(this.paginatedCollection,"page:change:after",self.render);
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!")
}
});