Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Backbone.js 主干木偶渲染器_Backbone.js_Rendering_Marionette_Backbone Views_Backbone Events - Fatal编程技术网

Backbone.js 主干木偶渲染器

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

当从代码的其他部分触发page:change:after事件时,我试图重新呈现木偶项视图。我尝试了两种方法:

一,

二,

出于某种原因,2可以工作,但不是1。虽然我可以在控制台上看到page:change:after,但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!")
        }

});

在第一个示例中,您没有执行该方法-应该是“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!")
        }

});