define(["paginator"],function(e) {
return Backbone.PageableCollection.extend({
url:"data/cart.php",
mode: "server",
state: {
pagesInRange: 0,
pageSize: 2 //这个限定不了
},
queryParams: {
currentPage: "page",
pageSize: "limit"
},
parseState: function(resp, queryParams, state,options) {
return {
totalRecords: resp.count
}
},
parseRecords: function(resp,options) {
console.log(resp.data) //这个输出如图上面部分
return resp.data
}
});
})
views识图输出
define(["collection"],function (Collection) {
var view= Backbone.View.extend({
initialize: function () {
this.collection = new Collection();
this.collection.on('sync',this.render,this);
this.collection.fetch(),
},
render: function () {
console.log(this.collection.toJSON())这个输出如图下面部分
}
});
return view;
})
JSON数据
{
"count":29,
"data":[{
"id":1
},
{
"id":2
},
{
"id":3
},
{
"id":4
}]
}
理论上下面应该显示的length是2;因为我的pageSize设置了2
是不是因为我的数据值是前端模拟的缘故,这个是传递哈希地址,然后传回来是2条,不应该是我模拟的?
这个是后端产生的;要相互约定好,_count总数量,限制条数为的就是分页(智能的)