我有下拉选项来自使用ng-repeat的数组。它正常工作。但我想以不同的方式。如果选择了一个选项,则应在其他下拉列表中禁用该选项。我们可以在棱角分明吗?
<div ng-app="myApp" ng-controller="MyCtrl">
<div ng-repeat="address in addresses">
Billing State:
<select
ng-model="address.state"
ng-options="state.lookupCode as state.description for state in lov_state"></select>
<tt>State selected: {{address.state}}</tt>
</div>
</div>
控制器代码:
var myApp = angular.module('myApp', []);
myApp.controller('MyCtrl', function($scope) {
$scope.addresses = [
{'state': 'AL'},
{'state': 'CA'},
{'state': 'FL'}
];
$scope.lov_state = [
{'lookupCode': 'AL', 'description': 'Alabama'},
{'lookupCode': 'FL', 'description': 'Florida'},
{'lookupCode': 'CA', 'description': 'California'},
{'lookupCode': 'DE', 'description': 'Delaware'}
];
});
请帮我这样做。这是jsfiddle链接。
答案 0 :(得分:2)
您可以在disable
关键字之前的某个位置使用ng-options
,使用disable when condition
中提供的for
选项。
<div ng-repeat="address in addresses">
Billing State:
<select ng-model="address.state" ng-change="checkSelected(address.state)"
ng-options="state.lookupCode as state.description disable when (address.state != state.lookupCode && state.selected) for state in lov_state">
</select>
<tt>State selected: {{address.state}}</tt>
</div>