嗨,我有一个保留的问题,在分页的尖锐湿页。我的意思是阻止分页1,但它没有显示为0。需要找到一个条件吗?
$scope.setPage = function (index) {
$scope.items.paging.offset = index;
console.log(index);
};发布于 2016-04-19 21:49:46
paginator.html
以下代码:
<ul class="pagination">
<li ng-repeat="index in [getSelectedPage() - 1 , getSelectedPage(), getSelectedPage() + 1]"
ng-click = "setPage(index)">
<a href="#" class="btn btn-primary">{{ index + 1 }}</a>
</li>
</ul>可以重新设计成类似这样的东西:
<ul class="pagination">
<li ng-repeat="index in getPaginationButtons()"
ng-click = "setPage(index)">
<a href="#" class="btn btn-primary">{{ index + 1 }}</a>
</li>
</ul>paginator.js
可以添加以下代码:
// but IMHO it's not very good to hardcode 3 buttons
// and not to check a number of available pages
$scope.getPaginationButtons = function () {
var buttons = [];
// TODO: fix offset or set it to 0
// if $scope.items.paging.offset is out of valid range
// for example, someone removes all items
// from another tab or window or browser
// and then you click on the page offset
// which is not present
if ($scope.items.paging.offset > 0) {
buttons.push($scope.items.paging.offset - 1);
}
buttons.push($scope.items.paging.offset);
// TODO: do the following only if the next page is present
buttons.push($scope.items.paging.offset + 1);
return buttons;
};发布于 2016-04-25 04:27:41
我想下面的部分可以在suggested code中改进
if ($scope.items.paging.offset > 0) {
buttons.push($scope.items.paging.offset - 1);
}
buttons.push($scope.items.paging.offset);
// TODO: do the following only if the next page is present
buttons.push($scope.items.paging.offset + 1);并应替换为以下内容:
// if not a first page then add a number of previous one
if ($scope.offset > 0) {
buttons.push($scope.offset / $scope.limit - 1);
}
buttons.push($scope.offset / $scope.limit);
// if there are more pages then show button of the next one
if (($scope.offset + $scope.limit) < $scope.total) {
buttons.push($scope.offset / $scope.limit + 1);
}以及你最新的柱塞示例中的以下代码(例如,来自https://plnkr.co/edit/N8HZ6qCtsj0fF4YMULFW):
function getPageCount() {
return Math.ceil($scope.total / $scope.limit);
}应该被弃用/删除。
并且下面的页面索引到的偏移量的计算应该使用IMHO:
$scope.setPage = function (index) {
$scope.offset = index * $scope.limit;
};https://stackoverflow.com/questions/36717949
复制相似问题