angularJS过滤器适用于两种情况

时间:2014-08-20 07:07:57

标签: javascript angularjs angularjs-filter

我有这个类别的json数组

$scope.categories=     [{
         "name": "Sport",
         "value":"SPORT",
        "image": "images/Layer-1.png"
        },{
         "name": "Theater",
         "value":"THEATER",
        "image": "images/Layer-2.png"
        },{
         "name": "Restaurant",
         "value":"RESTAURANT",
        "image": "images/Layer-3.png"
        },{
         "name": "Concert",
         "value":"CONCERT",
        "image": "images/Layer-4.png"
        },{
         "name": "Nightlife",
         "value":"THEATER",
        "image": "images/Layer-2.png"
        }];

我通过ng-click

发送此功能
 $scope.sendCategory = function(category) {

     $scope.search = category;
     //alert(category);



  };

我在HTML中有过滤器

filter:{itemType:search} 

它的工作完美。现在我想让它像分类是"夜生活"它显示了音乐会和剧院,因为没有数据有itemType = nightlife; 所以如何让它像其他它一样工作,因为它工作,但夜生活搜索将是音乐会和戏剧

1 个答案:

答案 0 :(得分:0)

我认为你应该使用过滤功能。像这样:

filter:function(value){return ['concert','theater'].indexOf(value.itemType) !== -1;}