过滤angularjs中单列中的多个值

时间:2017-03-20 20:29:06

标签: angularjs filter

我怎么能回到几个名字:[苹果,橘子,胡萝卜] [http://jsfiddle.net/GruffBunny/QHtD8/2/] 1

function MyCtrl($scope) {
    $scope.products = [
        {id:"1",type:"fruit"},
        {id:"2",type:"meat"},
        {id:"3",type:"drink"},
        {id:"4",type:"vegetable"},
        {id:"5",type:"dairy"}
    ];

    $scope.fruitOrVeg = function(product){
        return product.name == ['1','4','5'];
    };

非常感谢

2 个答案:

答案 0 :(得分:0)

更改模板,调用功能:

System.out.print

和过滤功能,返回新功能

<li ng-repeat="item in products | filter:fruitOrVeg()">{{item.name}}</li>

};

添加了JSFiddler

答案 1 :(得分:0)

尝试使用AngularJS custom filter

app.filter('filterByFruitOrVeg', function() {
   return function(array) {
       arr = arr.filter(payment, function(objectInArray) {
            return objectInArray.type === 'fruit' || objectInArray.type === 'vegetable';        
       });
   }
});