如何使angularjs $资源中的服务器端分页? [英] how to make a server side pagination with angularjs $resource ?

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

问题描述

我试图用一个大集合的元素显示一个表格。我想分页表,仅装入当前页面上显示的内容。现在,JSON装有 $资源

这里

我看了 的,这是一个好主意,通过JSON里面的分页的相关信息(当前页,pagesCount和elementsCount)头。

如何访问到那些从角?JSON的头的相关信息

下面是基本的js结构:

angular.module('App.services',['ngResource'])。
工厂('名单',函数($资源){
    返回$资源(URL / / JSON /中:类型/:身份证',{类型:@类型,ID:'@ ID'});
});
angular.module('App.controllers',[])。
控制器('的ListCtrl',['$范围','名单',函数($范围,列表){
    变量$ scope.list = List.query({偏移:0,上限:100,sortType:'DESC'});
}]);


解决方案

根据该AngularJS $资源文件时,它应该能够做到这一点:

  List.query({偏移:0,上限:100,sortType:'DESC'},功能(数据,responseHeaders响应){
  //你可以在这里访问头
});

I am trying to display a table with a large collection of elements. I want to paginate the table and load only the elements displayed on the current page. Now, the json is loaded with $resource.

I read here that it's a good idea to pass the pagination infos (currentPage, pagesCount and elementsCount) inside the json header.

How can I access to those infos which are in the json header from angular?

Here is the basic js structure:

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' });
}]);

解决方案

Based on the AngularJS $resource documentation, it should be possible to do this:

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

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

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