你如何根据Angular.js中的css类进行过滤?

时间:2014-02-08 17:49:10

标签: css angularjs filter

我正在尝试根据css类过滤我的结果,似乎无法想到最简单/最好的方法。

这是我的plunker example

基本上通过点击链接,我希望我的过滤结果只显示使用“in_red”类的项目。

1 个答案:

答案 0 :(得分:2)

不是按类过滤,而是按对象的实际属性进行过滤。完成所有类 后,根据name属性设置。

一种解决方案是使用自定义过滤功能:

ng-repeat="friend in friends | filter:filterFriends"

filterFriends的位置如下:

function(friend) {
  if ($scope.filterOnRed === true) {
    return friend.name.substring(0,1) == 'J';
  } else {
    return friend.name.indexOf($scope.searchText) != -1;
  }
}