我正在尝试在初始获取后从服务器加载其他模式Paginator.clientPager
这是我的收藏,几乎是从 github 上的示例代码复制粘贴的。
return new (Backbone.Paginator.clientPager.extend({
model: model,
paginator_core: {
type: 'GET',
dataType: 'json',
url: '/odata/LibraryFile'
},
paginator_ui: {
// the lowest page index your API allows to be accessed
firstPage: 1,
// which page should the paginator start from
// (also, the actual page the paginator is on)
currentPage: 1,
// how many items per page should be shown
perPage: 2,
// a default number of total pages to query in case the API or
// service you are using does not support providing the total
// number of pages for us.
// 10 as a default in case your service doesn't return the total
totalPages: 5
},
server_api: {
// number of items to return per request/page
'$skip': function () { return this.perPage * (this.currentPage - 1) },
'$top': function () { return this.perPage },
},
parse: function (response) {
console.log(response);
return response.value;
}
}))();
我这样调用初始提取
myCollection.fetch({
success: function(){
myCollection.pager();
},
silent:true
});
然后,在用户使用 clientPager 浏览了本地页面后,他可能想要加载更多页面,而不删除第一页。
我尝试像这样实现这一点,但由于某种原因,在我调用pager();
2 条新记录后被删除。
myCollection.currentPage = 2;
myCollection.fetch({
success: function(){
console.log(myCollection.length) // 4 models, with correct data
myCollection.pager();
console.log(myCollection.length) // the 2 new records are removed
},
silent:true,
remove: false // don't remove old records
});
我在做什么错,我怎样才能用它再加载 2 页Paginator.clientPager
?
我不想使用requestPager,因为我认为至少我不能在内存中进行预缓存。