我尝试在模型下进行分页。我可以正确地移动箭头,具体取决于我带来的记录数。但是,根据要显示在页面上的“最大行数”,数据不会被取消/减少/增加。
请在下面的Fiddle
中找到我使用的参考示例是Here
/*************
Start of logic for Paging
******/
self.items = ko.observableArray();
this.all = self.items;
self.pageNumber = ko.observable(0);
self.nbPerPage = 2;
// I think this is somewhere I am missing the functionality.
this.totalPages = ko.computed(function() {
var div = Math.floor(self.all().length / self.nbPerPage);
div += self.all().length % self.nbPerPage > 0 ? 1 : 0;
return div - 1;
});
this.paginated = ko.computed(function() {
var first = self.pageNumber() * self.nbPerPage;
return self.all.slice(first, first + self.nbPerPage);
});
this.hasPrevious = ko.computed(function() {
return self.pageNumber() !== 0;
});
this.hasNext = ko.computed(function() {
return self.pageNumber() !== self.totalPages();
});
this.next = function() {
if(self.pageNumber() < self.totalPages()) {
self.pageNumber(self.pageNumber() + 1);
}
}
this.previous = function() {
if(self.pageNumber() != 0) {
self.pageNumber(self.pageNumber() - 1);
}
}
/***********
End of Logic for Paging
* /
答案 0 :(得分:2)
您只需要从...更新视图即可。
<tbody data-bind="foreach: items " >
到
<tbody data-bind="foreach: paginated " >