angularjs 基于数组长度的 ng-repeat 过滤器

angularjs ng-repeat filter based on array length

我想知道,如何放置一个 ng-repeat 过滤器,它只会带回有颜色的项目?我希望在名为 "Show ones with colours" 的网格上方有一个复选框,它会在选中时根据颜色数组的计数过滤列表,并在未选中时显示全部。

{
   "_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"]
},

我认为您可以使用控制器功能来测试颜色的存在 所以在 haml/coffeescript

%tr{"ng-repeat2 => "item in list | filter: hasColour(item)"}

而 hasColour 是一个控制器函数

 $scope.hasColour=  (item) ->
  item.colours.length > 0

恐怕还没有测试

下面给大家没有颜色的:

<div ng-repeat="item in items | filter: { colours: '!' }">

再次取反,每个人都有颜色:

<div ng-repeat="item in items | filter: { colours: '!!' }">

演示: http://plnkr.co/edit/oIl3ohe0TLMWcQlTPuY5?p=preview