11
我需要能夠過濾對象的一個字段的兩個不同值。以下面的例子。對一個字段的多個值使用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']}"
但是沒有奏效。我認爲應該有一個簡單的解決方案,但我找不到它。