你好,全能的社区,
我正在尝试将 bbGrid 与backbone-pageable 一起使用。我已经设法使分页正常工作,因为我可以将 page 和 per_page 发送到服务器,并且 bbGrid 显示正确的项目数和页码。但我无法在网格中进行分页,因为我的集合没有返回正确的长度值。
这是我的收藏:
define([
'backbone-pageable',
'models/DeliveryModel'
], function(BackbonePageable, DeliveryModel) {
var DeliveryCollection = Backbone.PageableCollection.extend({
model : DeliveryModel,
url : '/UIServices/rs/material/v1/deliveries',
// Parse server response to handle total number of items
parseState: function (resp, queryParams, state, options) {
return {totalRecords : parseInt(options.xhr.getResponseHeader("X-Result-Counter"))};
}
});
return DeliveryCollection;
});
我期望collection.length返回X-Result-Counter的值,但它总是返回per_page的值。我错过了什么?
最佳答案
collection.length
返回集合中包含的模型的长度。在本例中,它是 per_page
长度,因为集合中仅存储当前页面的模型。
如果你想检索总长度,你应该使用collection.state.totalRecords
。
关于javascript - 如何获得主干分页以返回正确的长度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19318404/