gpt4 book ai didi

javascript - knockout : Table Paging

转载 作者:行者123 更新时间:2023-11-30 14:28:00 24 4
gpt4 key购买 nike

我尝试在我的模型下进行分页。我可以根据我拥有的记录数量正确地让 Arrow 移动。但数据不会根据要在页面上显示的最大行数而反射(reflect)/减少/增加。

请在下面找到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

*/

最佳答案

您只需要从...更新您的 View

<tbody data-bind="foreach: items " >

<tbody data-bind="foreach: paginated " >

关于javascript - knockout : Table Paging,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51638095/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com