AngujarJS server-side pagination grand total items using $resource

本小妞迷上赌 提交于 2019-12-08 01:57:32

问题


I'm trying to implement server-side pagination on an AngujarJS app but haven't figured out how to get the grand total (not the per-request total) items in a given JSON response without having to do an additional request:

$scope.books = [];
$scope.limit = 3;
$scope.offset = 0;

$scope.search = function () {
    Books.query({ q: $scope.query, limit: $scope.limit, offset: $scope.offset },
        function (response) {
            $scope.books = response;
        }
    );
};

$scope.previous = function () {
    if ($scope.offset >= $scope.limit) {
        $scope.offset = $scope.offset - $scope.limit;
        $scope.search();
    }
}

$scope.next = function () {
    if ($scope.offset <= $scope.limit) {
        $scope.offset = $scope.offset + $scope.limit;
        $scope.search();
    }
}

I've been looking at great contributed directives such as ng-table and ng-grid which already implement this as well as other useful features but I just want to be able to implement this one functionality from scratch to really learn the basics.


回答1:


Sounds like you are struggling with your api more than angular.

See the answer below for suggestions for the api.

What’s the best RESTful method to return total number of items in an object?



来源:https://stackoverflow.com/questions/19140017/angujarjs-server-side-pagination-grand-total-items-using-resource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!