Angular.js.如何计算满足自定义过滤器的 ng-repeat 迭代 [英] Angular.js. How to count ng-repeat iterations which satisfy the custom filter
本文介绍了Angular.js.如何计算满足自定义过滤器的 ng-repeat 迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
过滤器:
Kb.filter("notEmpty", function(){返回函数(输入){无功输出=[];for(var i=0;i
我需要根据循环中过滤项目的数量显示/隐藏重复的 s.最好的方法是什么?
谢谢
解决方案
ng-repeat
表达式允许将过滤后的结果分配给变量.此变量可从当前范围访问,因此您可以在同一范围内以任何方式使用它:
<p>过滤项目数:{{filteredItems.length}}</p>
Here's my code:
<div ng-show="?" ng-repeat="item in items | notEmpty">
</div>
Filter:
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?
Thanks
解决方案
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-repeat 迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文