2016-12-23 1 views
0

4 가지 옵션이있는 드롭 다운 목록이 있습니다. 'John (1)'이라는 첫 번째 옵션을 선택하고 행을 추가합니다. 이제 다음 드롭 다운은 드롭 다운에 3 개의 옵션 만 표시합니다. 즉, 이전 드롭 다운 선택 값 인 'John (1)'을 제외해야합니다. 다음 행을 추가 할 때 이전에 선택된 두 개의 드롭 다운 값을 제외해야합니다. 이것이 성취 될 수 있는가? 미리 감사드립니다. 아래는 바이올린입니다.이미 선택된 값을 기준으로 다음 드롭 다운 값 필터링

$scope.notSelected = function(item){ 
     for (var i in $scope.viewTemplateRow){ 
      if ($scope.viewTemplateRow[i].id==item.id) 
      return false 
     } 
     return true; 
    } 

귀하의 HTML은 다음과 같이 표시됩니다 :

<option ng-repeat="option in viewTemplateData | filter: notSelected" value="{{option.id}}" ng-selected="{{option.id == mapping.id}}" ng-model="viewTemplateData">{{option.name}} ({{option.id}})</option> 

<div ng-app ng-controller="LoginController"> 
    <table class="table table-striped"> 
    <thead> 
     <tr> 
      <th>Description</th> 
     </tr> 
    </thead> 
    <tbody> 
     <tr ng-repeat="mapping in viewTemplateRow"> 
      <td> 
       <select class="form-dropdown" id="templateId" ng-model="mapping.id"> 
        <option value="">Please Select...</option> 
        <option ng-repeat="option in viewTemplateData" value="{{option.id}}" ng-selected="{{option.id == mapping.id}}" ng-model="viewTemplateData">{{option.name}} ({{option.id}})</option> 
       </select> 
      </td> 
     </tr> 
    </tbody> 
</table> 
<button type="button" class="button button-compact" ng-click="addRow();">Add New Row</button> 
</div> 

https://jsfiddle.net/Lt7aP/3787/

답변

0

allready 추가 개체를 방지하기 위해 당신의 NG-반복에 필터를 추가 : 선택기 항목에 대한 ng-options에 대한 ng-repeat 지시문을 대체하는 것이 좋습니다.

+0

내가보기에 문제는 양방향 데이터 바인딩 때문에 모든 드롭 다운을 수정한다는 것입니다. 고유 한 옵션 값 세트로 각 드롭 다운을 만들고 싶습니다. 예를 들어 첫 번째 드롭 다운에는 '1', '2', '3', '4'와 같은 옵션이 있어야합니다. '1', '2', '3', '4'등의 옵션을 유지하면서 '2', '3', '4' 여전히 손상되지 않았습니다. – Maverick2007

+0

angular.copy()를 사용하여 객체를 복사하고 양방향 데이터 바인딩에 대한 참조를 잃을 수 있습니다. –

+0

는 angular.copy()를 사용하여 시도했지만 위에 언급 한대로 원하는 출력을 얻지 못했습니다. – Maverick2007

관련 문제