Angular.js。怎么算满足定制过滤器NG-重复迭代 [英] Angular.js. How to count ng-repeat iterations which satisfy the custom filter
本文介绍了Angular.js。怎么算满足定制过滤器NG-重复迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我的code:
<div ng-show="?" ng-repeat="item in items | notEmpty">
</div>
过滤器:
Kb.filter("notEmpty", function(){
return function(input){
var output=[];
for(var i=0;i<input.length;i++){
if(input[i]){
output.push(input[i]);
}
}
return output;
}});
我需要显示/按照在循环过滤项目的数量隐藏重复第
什么是做到这一点的最好方法是什么?
I need to show/hide repeated s according the quantity of filtered items in the loop. What is the best way to do it?
感谢
推荐答案
NG-重复
前pression允许过滤后的结果分配给一个变量。这个变量将是从当前范围访问,因此您可以在同一范围内使用任何你想要的:
ng-repeat
expression allows filtered results to be assigned to a variable. This variable will be accessible from current scope so you can use it in same scope anyway you want:
<p>Number of filtered items: {{filteredItems.length}}</p>
<div
ng-show="filteredItems.length > 0"
ng-repeat="item in filteredItems = (items | notEmpty)"
>
{{$index}}
</div>
这篇关于Angular.js。怎么算满足定制过滤器NG-重复迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文