2014-12-27 4 views
1

제품 배열이 있습니다 .i 형식 키를 필터링하려고합니다. 나는 야채와 과일 만 함께 보여주고 싶다. 각도 키의 단일 키와 다중 값에 필터를 설정하는 방법.하나의 키를 여러 개의 값으로 필터링하기

<div ng-controller="MyCtrl"> 
     <ul> 
      <li ng-repeat="item in products | filter:({type:'vegetable'}||{type:'fruit'})">{{item.name}}</li> 
     </ul> 
    </div> 

    var myApp = angular.module('myApp', []); 

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

답변

0

가장 간단한 해결 방법은 컨트롤러에 필터를 추가하고 사용하는 것입니다 : 엘러리 @wayne

$scope.filterFruitsAndVegies = function (item) { 
    return item.type === 'fruit' || item.type === 'vegetable'; 
}; 
<div ng-controller="MyCtrl"> 
    <ul> 
     <li ng-repeat="item in products | filter: filterFruitsAndVegies">{{item.name}}</li> 
    </ul> 
</div> 

http://plnkr.co/edit/HhZ49dpylTRJMVnSKdyt?p=preview

+0

감사하지만 우리는 밖으로 작성하여이 작업을 수행 할 수 있습니다 맞춤 필터? – user3398632

+0

제 이해는 아니오입니다. 다음과 같은 답변으로 몇 가지 질문이 있습니다. http://stackoverflow.com/questions/21987904/angular-js-ng-repeat-filter-by-property-having-one-of-multiple-values- or-of-val –

+0

ok @wayneEllery 감사합니다. – user3398632

관련 문제