ng-repeat only objects with specific property value - custom filter?

ぐ巨炮叔叔 提交于 2019-12-22 12:23:49

问题


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.


回答1:


The built in filter can handle this case...

<div ng-repeat="user in users | filter : {role: 'administrator'} : true">
   ...
</div>


来源:https://stackoverflow.com/questions/24473001/ng-repeat-only-objects-with-specific-property-value-custom-filter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!