Backbone Paginator Collection不会在重置时触发渲染

我有一个Backbone Paginator系列:

var ExercisesCollection = Backbone.Paginator.requestPager.extend({ model: ExerciseModel, paginator_core: { url: "/exercises" }, paginator_ui: { firstPage: 1, currentPage: 1, perPage: 10, totalPages: 10 }, server_api: { "filter": "", "categories": "", "top": function() { return this.perPage; }, "skip": function() { return this.currentPage * this.perPage; } }, parse: function (response) { this.totalPages = response.meta.totalPages; return response.data; } }); 

我在Backbone View中使用它,如下所示:

 var Exercises = Backbone.View.extend({ initialize: function () { this.collection = new ExercisesCollection(); this.collection .on( "reset", this.render, this ) .on( "change", this.render, this); this.collection.goTo( 1 ); }, render: function() { alert("bah!"); } }); 

通过查看网络活动,我可以看到它正在将请求发送到服务器并接收适当的响应。 但它从不调用渲染function。 重置和更改事件似乎不起作用。

我有什么想法我做错了吗?

谢谢

我在2016年有同样的问题:)
当您使用'server'模式时,您需要收听'sync'事件,而不是'reset'

 // in a view this.listenTo(this.collection, 'sync', this.renderPage); 

来自骨干文档( http://backbonejs.org/#Collection-fetch ):

当模型数据从服务器返回时,它使用set来(智能地)合并获取的模型,除非您传递{reset:true},在这种情况下,集合将被(有效地)重置。

因此默认情况下它不会调用reset() ,因此没有'reset'事件。

我在这个答案中发现了'sync'事件: https : //stackoverflow.com/a/17053978/1657101

从骨干1.0开始,model.fetch()触发’同步’。 这就是你应该绑定的东西。