ng-repeat 仅具有特定属性值的对象 - 自定义过滤器? [英] ng-repeat only objects with specific property value - custom filter?
问题描述
假设我有一个 JSON 对象user",它具有一些基本属性,例如:name"、address"、role"等.
我希望 ng-repeat 只吐出属性角色"等同于管理员"的对象.我该怎么做?
我在想像自定义过滤器这样的东西,或者可能制作一个范围变量,我将匹配的对象放入数组中,然后重复它们.
这种情况下的最佳做法是什么?
谢谢.
内置的 filter 可以处理这个案子...
<div ng-repeat="user in users | filter : {role: 'administrator'} : true">...
So say I have a JSON object 'user' with some basic properties like: 'name', 'address', 'role', etc.
I want the ng-repeat to only spit out the objects in which the property 'role' equates to 'administrator'. How would I go about doing that?
I'm thinking something like a custom filter, or possibly making a scope variable where I put the matching objects in an array, and then repeat through them.
What is the best practice for this case?
Thanks.
The built in filter can handle this case...
<div ng-repeat="user in users | filter : {role: 'administrator'} : true">
...
</div>
这篇关于ng-repeat 仅具有特定属性值的对象 - 自定义过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!