【发布时间】:2013-02-03 20:31:28
【问题描述】:
我有一个 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;
}
});
我像这样在主干视图中使用它:
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!");
}
});
通过查看网络活动,我可以看到它正在向服务器发送请求并接收到适当的响应。但是它从不调用渲染函数。重置和更改事件似乎不起作用。
任何想法我做错了什么?
谢谢
【问题讨论】:
-
this.collection 你定义了吗?
-
是的 this.collection 是 Paginator Collection 的一个实例
-
.on("add", this.render, this) ?
-
试过了 - 不幸的是没有。
-
我不熟悉Backbone.Paginator,你能用普通的骨干集合测试一下吗?
标签: javascript jquery backbone.js