2014-04-30 4 views
2

아래 JSON 데이터에서 가져온 카테고리 드롭 다운 목록을 가져 오려고합니다. 컴퓨터angularjs가 ngrepeat에서 중복 값을 제거합니다.

[ 
{ 
"title":"C Programming", 
"category":"Computer" 
}, 
{ 
"title":"International Tax", 
"category":"Business" 
}, 
{ 
"title":".net Programming", 
"category":"Computer" 
} 
//more data... 
] 

AngularJS와 : 저는 예를 들어 같은 범주를 여러 번,이

function showSubjects($scope, $http) 
{ 
$http({method: 'POST', url: 'js/subjects.json'}).success(function(data) 
{ 
$scope.items= data; // response data 
}); 
} 

HTML :

내가 한 번만 중복 범주를 표시 할
<div id="ng-app" ng-app ng-controller="showSubjects"> 
<select> 
<option ng-repeat="subjects in items">{{subjects.category}}</option> 
</select> 
</div> 

. 제게 몇 가지 제안을하고, 필요한 출력을 달성하는 방법을 알려주십시오. 미리 감사드립니다. 더 여기

+1

중복 된 http://stackoverflow.com/questions/15914658/angular-js-how-to-make-ng-repeat-filter-out-duplicate-results –

답변

1

사용

<option ng-repeat="subjects in items | unique:'category'">{{subjects.category}}</option> 

봐 : Unique & Stuff

1

당신은 아래와 같이 자신의 기능을 사용할 수 있습니다 :

<select name="cmpPro" ng-model="test3.Product" ng-options="q for q in productArray track by q"> 
    <option value="" >Plans</option> 
</select> 

productArray =[]; 
angular.forEach($scope.leadDetail, function(value,key){ 
var index = $scope.productArray.indexOf(value.Product); 
if(index === -1) 
{ 
    $scope.productArray.push(value.Product); 
} 

});

+0

답변에 코드를 지정하십시오. –

관련 문제