AngujarJS使用$资源服务器端分页,总计项目 [英] AngujarJS server-side pagination grand total items using $resource

查看:232
本文介绍了AngujarJS使用$资源服务器端分页,总计项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现在一个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.

<一个href=\"http://stackoverflow.com/questions/3715981/whats-the-best-restful-method-to-return-total-number-of-items-in-an-object\">What's最好的RESTful方法返回一个对象的项目总数?

这篇关于AngujarJS使用$资源服务器端分页,总计项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆