AngularJS 过滤一个字段的几个值

我需要能够过滤两个对象字段的两个不同的值。 采取以下例子。


$scope.products = [
{name:"Apple",type:"fruit"},
{name:"Grape",type:"fruit"},
{name:"Orage",type:"fruit"},
{name:"Carrot",type:"vegetable"},
{name:"Milk",type:"dairy"}
]


过滤器
ng-repeat="item in products | filter:{type:'fruit'}"

. 我可以得到所有的水果。 但如果我想让所有的水果和蔬菜怎么办? 我试过了


ng-repeat="item in products | filter:{type:['fruit','vegetable']}"


但它没有工作。 我认为必须对这个问题有一个简单的解决方案,但我找不到它。

http://jsfiddle.net/QHtD8/
已邀请:

帅驴

赞同来自:

相反,使用过滤器功能:


$scope.fruitOrVeg = function/product/{
return product.type == 'fruit' || product.type == 'vegetable';
};

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


http://jsfiddle.net/GruffBunny/QHtD8/2/

要回复问题请先登录注册