对两个嵌套的ng重复进行角度自定义过滤
Angular custom filtering on two nested ng-repeat
>我有一个这样的数组数据:
[
{
firstName: "John",
lastName: "Adams",
calls: [
{
date: "2014-08-13",
number: 123456789,
operatorName: "Bla-Bla 1"
},
{
date: "2014-08-18",
number: 987654321,
operatorName: "Bla-Bla 2"
},
{
date: "2014-11-06",
number: 123456543,
operatorName: "Bla-Bla 1"
},
{
date: "2014-10-15",
number: 987654567,
operatorName: "Bla-Bla 3"
}
]
},
{
firstName: "Jonnie",
lastName: "Bravo",
calls: [
{
date: "2014-05-09",
number: 534535367,
operatorName: "Bla-Bla 1"
},
{
date: "2014-01-25",
number: 089086464,
operatorName: "Bla-Bla 1"
}
]
},
{
firstName: "Ricky",
lastName: "Lambert",
calls: [
{
date: "2014-10-19",
number: 147258369,
operatorName: "Bla-Bla 3"
},
{
date: "2014-11-01",
number: 798908645,
operatorName: "Bla-Bla 2"
},
{
date: "2014-11-05",
number: 312315367,
operatorName: "Bla-Bla 3"
}
]
}
]
我正在使用 Angular 像这样遍历所有客户:
<div ng-repeat="customer in customers">
<span ng-repeat="call in customer.calls">
<span class="name">{{ customer.name }}</span>
<span class="info">{{ call.date }} - {{ call.number }} - {{ call.operatorName }}</span>
</span>
</div>
输出是这样的:
约翰·亚当斯
2014-08-13 - 123456789 - Bla-Bla 1
约翰·亚当斯
2014-08-18 - 987654321 - 布拉布拉2
。
琼妮·布拉沃
2014-05-09 - 534535367 - Bla-Bla 1
。
瑞奇·兰伯特
2014-11-05 - 312315367 - Bla-Bla 3
我现在遇到的问题是我想过滤数据以显示所有调用运算符Bla-Bla 1
的用户。我搜索了嵌套的ng重复,但没有任何帮助。请记住,我希望我的数据像这样显示。
希望你能很好地理解我。有什么想法吗?:)
add
ng-if="call.operatorName=='Blabla 1'"
到第二ngRepeat
您还可以使用过滤器过滤数据:
ng-repeat="call in customer.calls | filter:{operatorName:'Bla-Bla 1'}"
或一些习俗:
ng-repeat="call in customer.calls | operatorF:'Bla-Bla 1'"
$scope.operatorF = function(){
return function(calls, op) {
if (!op) return calls;
return calls.filter(function(call){
return call.operatorName === op
});
};
}
甚至更好:
ng-repeat="call in customer.calls | filter:operator:'Bla-Bla 1'"
$scope.operator = function(call, op){
if (!op) return true;
return call.operatorName === op
};
而且你不能不循环。
您也可以手动检查更改并更新过滤集:
ng-repeat="call in customer.filteredCalls"
$scope.$watch('customer.calls', function(){
$scope.customer.filteredCalls = $scope.customer.calls.filter(myFilterFn);
});
"filter"过滤器应该可以正常工作:
<span ng-repeat="call in customer.calls | filter:{operatorName:'Bla-Bla 1'}">...</span>
您可以通过
各种不同的方式实现此目的:使用filter
、ng-if
或ng-hide
只是其中的几个。
如果您想了解幕后发生的事情以及最适合您的具体情况,这是一个有趣的话题。我建议查看此链接,以简短但很好地解释这些不同"过滤"机制之间的权衡:
过滤器与 ng 隐藏
相关文章:
- 自定义过滤淘汰js observableArray
- 剑道网格不允许我在使用自定义列模板时过滤列
- 通过单向绑定的过滤功能提高自定义角度下拉菜单中的角度性能
- Angular自定义过滤器在处理某些匹配时注销,但会过滤掉所有结果
- 对两个嵌套的ng重复进行角度自定义过滤
- 在 SlickGrid 中进行自定义过滤的最佳方式
- 使用AngularJS自定义可过滤下拉菜单
- 如何在Angular js中基于两个自定义过滤器过滤数据
- 具有多选列的剑道网格自定义过滤功能
- jqGrid-自定义过滤有效,但在模式窗口中重新打开网格后无效
- AngularJS对ngRepeat对象的高级自定义过滤
- 自定义正则表达式过滤掉最后一个url路径中的ID
- 自定义列表视图过滤用户输入
- 过滤谷歌地图自定义覆盖取决于他们是否落在当前的地图边界
- 使用ng-table自定义过滤/排序并选择
- 自定义过滤器对选定数组进行角过滤
- 在流星中使用angularjs自定义过滤
- angular在ngTables中的自定义过滤
- Telerik MVC网格-自定义过滤(客户端)
- 使用javascript过滤Telerik MVC网格不能与自定义绑定一起工作