我想知道,如何将过滤器放入 ng-repeat 中,使其仅带回有颜色的项目?我希望网格上方有一个名为“显示带有颜色的颜色”的复选框,该复选框将在选择颜色数组时根据颜色数组的计数过滤列表,并在取消选择时显示全部。
{
"_id": "54d13c3f3c25d5d8123a1d62",
"name": "Barry",
"colours": ["239, 101, 128"]
},
{
"_id": "54d13sfg5d5d8hgf6gg",
"name": "John",
"colours": []
},
{
"_id": "34d13sfg5d5d4tt6g",
"name": "Andrew",
"colours": []
},
{
"_id": "44d165d5d4t77t6g",
"name": "Gary",
"colours": ["25, 234, 22", "5, 100, 255"]
},
最佳答案
以下将给每个人没有颜色:
<div ng-repeat="item in items | filter: { colours: '!' }">
再次否定它,你就会让每个人都有颜色:
<div ng-repeat="item in items | filter: { colours: '!!' }">
关于基于数组长度的angularjs ng-repeat过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28398549/