我正在使用@michaelbromley的dir分页指令。我想得到当前指令页面上的所有记录。有办法这样做吗?

下面是链接:二次分页,所以我需要一个从100到96的5 records集合。有什么快捷的方法吗?
我试过几件事,但不起作用。
发布于 2015-04-28 10:48:10
下面是另一种可能的方法,它不需要您复制dir-paginate表达式中的逻辑:
对于每个重复的项,您只需将该项推入控制器中的数组中即可。这当然会给你这一页的所有项目。
下面是一个示例:
<ul>
<li dir-paginate="meal in perman = ( meals | filter:q ) | orderBy: order?'key':'-key' | itemsPerPage: pageSize" current-page="currentPage" ng-init="addMeal(meal)">{{ meal.key + ': ' +meal.val }}</li>
</ul>然后在控制器中:
$scope.addMeal = function(meal) {
if (meal) {
if ($scope.page.length === $scope.pageSize + 1) {
$scope.page = [];
}
$scope.page.push(meal);
}
}我还没有对它进行过昂贵的测试,但是一般的原则应该是可行的。在我看来,这有点麻烦,但作为Rathish提供的答案的替代方案,这是值得知道的。
发布于 2015-09-25 17:25:52
我遇到了同样的问题,但这里的答案并没有满足我的需求(或者说是想要的)。我决定自己解决这个问题,并决定创建一个过滤器,其唯一目的是记录在给定目标上的给定属性中通过它传递的项目。我想出了这个:
/**
* Author: Eric Ferreira <http://stackoverflow.com/users/2954747/eric-ferreira> ©2015
*
* This filter will sit in the filter sequence, and its sole purpose is to record
* the current contents to the given property on the target object. It is sort of
* like the 'tee' command in *nix cli.
*/
angular.module('app').filter('record', function() {
return function(array, property, target) {
if (target && property) {
target[property] = array;
}
return array;
}
});然后,在分页中使用筛选器(或者任何您想得到当前数组的地方-在使用搜索查询过滤、分页后、过滤当前页面等等-实际上认为)如下:
<div dir-paginate="item in items | itemsPerPage:pageSize | record:'currentPage':this">{{item.text}}</div>您还可以在一个序列中多次使用它:
<div dir-paginate="item in items | filter:searchQuery | record:'filtered':this | itemsPerPage:pageSize | record:'currentPage':this">{{item.text}}</div>上面的内容将同时记录当前页和当前筛选器查询产生的所有记录。
这将在$scope.currentPage中记录当前页面(并在更改时进行更新)。上面示例中的this是过滤器的目标。它决定为$scope.this,对于大多数意图和目的来说,它只是$scope。
在您的具体情况下,您将使用以下行(在模块中添加/要求筛选器之后),而用于分页:
<li dir-paginate="meal in perman = ( meals | filter:q ) | orderBy: order?'key':'-key' | itemsPerPage: pageSize | record:'currentPage':this">{{ meal.key + ': ' +meal.val }}</li>我用叉子叉了你的柱塞,以证明它也起作用了:
http://plnkr.co/edit/uC3RiC?p=preview
发布于 2020-09-17 12:50:49
是的,我们可以根据数据创建我们自己的逻辑。
Displaying {{ pageSize * (currentPage-1)+$index+1 }} - {{ pageSize*currentPage }} of {{ perman.length }}https://stackoverflow.com/questions/29837842
复制相似问题