【问题标题】:how to make a server side pagination with angularjs $resource ?如何使用 angularjs $resource 进行服务器端分页?
【发布时间】:2013-07-04 00:03:00
【问题描述】:

我正在尝试显示包含大量元素的表格。我想对表格进行分页并仅加载当前页面上显示的元素。现在,json 加载了$resource

我读到here,在 json 标头中传递分页信息(currentPage、pagesCount 和 elementsCount)是个好主意。

如何从 Angular 访问 json 标头中的那些信息?

这是基本的js结构:

angular.module('App.services', ['ngResource']).
factory('List', function($resource){
    return $resource('url/of/json/:type/:id', {type:'@type', id:'@id'});
});


angular.module('App.controllers', []).
controller('ListCtrl', ['$scope', 'List', function($scope, List) {
    var $scope.list= List.query({offset: 0, limit: 100, sortType: 'DESC' });
}]);

【问题讨论】:

标签: angularjs


【解决方案1】:

根据 AngularJS $resource 文档,应该可以这样做:

List.query({offset: 0, limit: 100, sortType: 'DESC' }, function(data, responseHeaders) {
  // you can access headers here
});

【讨论】:

  • 是的,这是显示上一页和下一页链接的方式,但如果我想显示每个页面的直接链接怎么办?我需要来自服务器的 (currentPage, PagesCount) 信息。还是我错过了什么?
  • 可以根据limitoffset计算。你知道那些。除非I 我错过了什么:)
  • 感谢您的回答。要计算分页,您需要 limitoffset 以及我想通过 json 标头传递的元素总数 (elementCount)。你觉得呢?
  • 工作!我必须像这样将参数传递给responseHeadersresponseHeaders("date")
猜你喜欢
  • 1970-01-01
  • 2016-06-22
  • 2013-10-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多