嗨我有保留问题,瑕疵页面。我的意思是阻止分页1并且没有显示为0.需要找到条件?
$scope.setPage = function (index) {
$scope.items.paging.offset = index;
console.log(index);
};
答案 0 :(得分:0)
以下代码:
<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>
可以添加以下代码:
// 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;
};
答案 1 :(得分:0)
恕我直言,可以在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);
}
以下代码来自您最新的plunker示例(即来自https://plnkr.co/edit/N8HZ6qCtsj0fF4YMULFW):
function getPageCount() {
return Math.ceil($scope.total / $scope.limit);
}
应该被弃用/删除。
应使用以下页面索引到偏移计算恕我直言:
$scope.setPage = function (index) {
$scope.offset = index * $scope.limit;
};