角度.js. 如何计算满足自定义过滤器的 ng 重复迭代
Angular.js. How to count ng-repeat iterations which satisfy the custom filter
这是我的代码:
<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;
}});
我需要根据循环中过滤项目的数量显示/隐藏重复的s。最好的方法是什么?
谢谢
ng-repeat
表达式允许将过滤结果分配给变量。可以从当前范围访问此变量,因此您可以根据需要在同一范围内使用它:
<p>Number of filtered items: {{filteredItems.length}}</p>
<div
ng-show="filteredItems.length > 0"
ng-repeat="item in filteredItems = (items | notEmpty)"
>
{{$index}}
</div>
最简单的方法可能是在控制器中运行筛选器。像这样:
function MyCtrl($scope, notEmptyFilter)
{
//$scope.items is put into the scope somehow
$scope.filteredItems = notEmptyFilter($scope.items);
}
那么你的 HTML 将看起来像这样:
<div ng-show="filteredItems.length > 0" ng-repeat="item in filteredItems">
</div>
从 Angular 1.3 开始,您可以使用以下语法进行ng-repeat
:
variable in expression as alias_expression
那是:
<p>Number of filtered items: {{filteredItems.length}}</p>
<div ng-repeat="item in items | notEmpty as filteredItems">
...
</div>
我找到了这个
如何显示过滤后的ng重复数据的长度,
描述在筛选列表后获取计数
相关文章:
- 如何在angular.js中动态应用自定义过滤器
- 自定义angularjs过滤器日期时间格式额外字符
- AngularJS自定义过滤器未触发点击事件
- AngularJS中货币过滤器的Javascript代码无法使用自定义符号
- Vue.js如何在定义API变量之前实现自定义过滤器
- 我们如何自定义内置的 Angular “货币”过滤器
- 用于分页的 AngularJS 自定义过滤器
- 为什么我的自定义过滤器会导致无限消化
- 如何仅在文本字段中有值时才将自定义过滤器应用于 ng-repeat
- 指令中的 AngularJS 自定义过滤器以格式化值
- Angular自定义过滤器在处理某些匹配时注销,但会过滤掉所有结果
- Angular js自定义过滤器未定义
- AngularJS自定义过滤器调用了两次,并在第二次调用时删除输入数据
- 自定义Angular.js过滤器在IE8中不返回任何内容,在Chrome/FF中运行良好
- 自定义角度过滤器提供TypeError.不能调用undefined,但变量已定义并有效
- 创建自定义角度过滤器
- 自定义过滤器的问题,我缺少什么
- 如何在Angular 1.3.6上创建一个自定义过滤器来搜索嵌套数组
- json数组angularjs中的自定义过滤器
- 两个日期之间的自定义过滤器 AngularJS