
本文介绍了确定 ng-repeat 过滤器显示多少结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我将 ng-repeat
与 filter
一起使用,我如何确定过滤掉了多少个元素(反之亦然,显示了多少个)?具体来说,我想创建一个用于创建过滤器的搜索栏,但我还想显示过滤器隐藏了多少元素(即类似于 Showing 6 of 10 results
).>
解决方案
请看这里 http://jsbin.com/xuyuy/1/edit
在您的中继器中,您可以创建新数组,即:personsfiltered
ng-repeat="person in peoplefilterd = (persons | filter : search )
然后只显示原始数组和过滤数组的长度:
显示 {{personsfilterd.length}} 个 {{persons.length }} 结果
完整代码在这里:
var app = angular.module('app', []);app.controller('fCtrl', function($scope) {$scope.persons = [迈克"、汤姆"、蒂姆"、吉姆"、肯"]});<div ng-app="app"><div ng-controller="fCtrl"><input type="text" ng-model = "search">显示 {{personsfilterd.length}} 个,共 {{persons.length }} 个结果<li ng-repeat="person in peoplefilterd = (persons | filter : search )">{{person}}</li>
If I use ng-repeat
with filter
, how can I determine how many elements are filtered out (or vice versa, how many are shown)? Specifically, I would like to create a search bar that creates the filter, but I would also like to show how many elements are hidden by the filter (ie something like Showing 6 of 10 results
).
解决方案
Please see here http://jsbin.com/xuyuy/1/edit
In your repeater you can create new array ie : personsfiltered
ng-repeat="person in personsfilterd = (persons | filter : search )
and after that just display length of orignal array and filtered array :
Showing {{personsfilterd.length}} of {{persons.length }} results
Full code here:
var app = angular.module('app', []);
app.controller('fCtrl', function($scope) {
$scope.persons = [
'Mike', 'Tom', 'Tim', 'Jim', 'Ken'
]
});
<div ng-app="app">
<div ng-controller="fCtrl">
<input type="text" ng-model = "search"> Showing {{personsfilterd.length}} of {{persons.length }} results
<li ng-repeat="person in personsfilterd = (persons | filter : search )">{{person}}</li>
</div>
</div>
这篇关于确定 ng-repeat 过滤器显示多少结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!