根据第一个选择筛选出第二个下拉列表。

时间:2017-07-26 14:46:24

标签: javascript angularjs

我希望second dropdown不包含first选项。如果我在第一个下拉列表中选择"Team1",则第二个下拉列表不应包含"Team1" and to contain the other ones.。反之亦然。

<div ng-app>
    <div ng-controller="TodoCtrl">
    <select ng-model="name" ng-options="f.name for f in devices"></select>
    <select ng-model="name" ng-options="f.name for f in devices 
               | filter:{id:name.id }" id="{{formEach.id}}">
        </select>
    </div>
</div>

以下是解决问题的小提琴 http://jsfiddle.net/x40ese02/

1 个答案:

答案 0 :(得分:0)

将过滤器更改为filter:{id:'!' + name.id}

function TodoCtrl($scope) {
    $scope.devices = [{
        id: "X000",
        name: 'Team 1',
        icon: 'ion-document-text',
        status: 'Owner',
        color: 'brown'
    }, {
        id: "X002",
        name: 'Team 2',
        icon: 'ion-document-text',
        status: 'Owner',
        color: 'yellow'
    }, {
        id: "X003",
        name: 'Team 3',
        icon: 'ion-document-text',
        status: 'Owner',
        color: 'black'
    }];   
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app>
    <div ng-controller="TodoCtrl">
    <select ng-model="name" ng-options="f.name for f in devices"></select>
    <select ng-model="name2" ng-options="f.name for f in devices | filter:{id: '!' + name.id }" id="{{formEach.id}}">
        </select>
    </div>
</div>