在阅读了很多分页插件后,我无法理解并手动创建了一个mongoose,angularjs,express,节点堆栈 现在,在我的客户端代码中,我有结果中的项目总数(每次更改页面时从服务器获取结果),因此它们是动态的,不会修复,因为可能会有实时更新。所以在我的ui我写作 -
div.pagination-user.pull-right
a.page.gradient(ng-class="{disabled:currentPage == 0}",ng-click="prevPage()") Prev
a.page.gradient(ng-repeat="n in range(1,totalItems)",ng-class="{active: n == currentPage}",ng-click="setPage()",ng-bind="n",ng-show="Math.abs(currentPage-n)<3") 1
a.page.gradient(ng-class="{disabled:currentPage == pagedItems.length-1}",ng-click="nextPage()") Next
我尝试了ng-show属性来检查n当前索引是否接近currentPage和ng-show是否条件类似于两端(因此代替(n-currentPage)我使用 Math.abs(currentPage-n))
我想这就是我出错的地方,但如果还有另一种方法可以限制客户端代码中可见的页面按钮数量,那么有人可以建议
如果在任何情况下我的控制器代码都会影响到它,则如下所示 -
angular.module('app').controller('PaginationDemoCtrl', function($scope,$filter, mvUser) {
$scope.itemsPerPage = 2;
$scope.currentPage = 1;
var paginatedResults = function(page){
var result = mvUser.query({page:page},function(res){
$scope.maxSize = 5;
$scope.totalItems = Math.ceil(res.count/$scope.itemsPerPage);
$scope.currentPage = res.current;
$scope.pagedItems = res.results;
},function(err){
console.log("some error");
})
};
$scope.setPage = function () {
$scope.currentPage = this.n;
paginatedResults($scope.currentPage);
};
$scope.prevPage = function () {
if ($scope.currentPage > 0) {
$scope.currentPage--;
paginatedResults($scope.currentPage);
}
};
$scope.range = function (start, end) {
var ret = [];
if (!end) {
end = start;
start = 0;
}
for (var i = start; i < end; i++) {
ret.push(i);
}
return ret;
};
$scope.nextPage = function () {
if ($scope.currentPage < $scope.totalItems - 1) {
$scope.currentPage++;
paginatedResults($scope.currentPage);
}
};
paginatedResults($scope.currentPage);
});