AngujarJS使用$资源服务器端分页,总计项目分页、服务器端、项目、资源

2023-09-13 04:09:26 作者:作业被我养的白白的

我想实现在一个AngujarJS应用服务器端分页,但还没有想出如何获得总计(而不是每个请求总计)在给定的JSON响应的物品,而无需做额外要求

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();
    }
}

我一直在寻找伟大的贡献指令,如 NG-表 NG-格这已经实现了这个问题,以及其他有用的功能,但我只是希望能够从头开始实现这个功能,真正了解的基础知识。

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.

推荐答案

听起来你与你的API超过角度挣扎。

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

请参阅下面的答案为api的建议。

See the answer below for suggestions for the api.

What's最好的RESTful方法返回一个对象的项目总数?