AngularJS动态分页:如何限制最大可见按钮

AngularJS dynamic pagination: how to limit the maximum visible buttons

本文关键字:按钮 何限制 动态 分页 AngularJS      更新时间:2023-09-26

看了很多分页插件,不懂,用mongoose, angularjs, express, node stack手工做了一个现在在我的客户端代码我有项目的总数在结果(结果从服务器每次页面更改获取)所以他们是动态的,而不是固定的,因为可能有实时更新。在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属性来检查当前索引是否接近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);
});

你试过用#ngTasty做分页吗?http://zizzamia.com/ng-tasty/