简体   繁体   English

在使用Angularjs的其他多选选项字段中禁用选定的选项

[英]Disable selected options in other multi select option fields of the using Angularjs

I am new to Angularjs. 我是Angularjs的新手。 I am appending dynamic multi select boxes, what is my question is, I want to disable all the selected options in other multi select boxes. 我要附加动态多选框,我的问题是,我想禁用其他多选框中的所有选定选项。 I have tried Disabled selected item in Angular for other Select Option Fields of the same Items the answer from the above link, but it is for select box not for multi select. 我已经尝试在Angular中为同一项目其他Select Option字段禁用Angular中的选定项目,答案是上述链接的答案,但这是针对选择框而不是针对多重选择的。 I have tried the answer for multi select, but there is some complication. 我已经尝试了多选的答案,但有一些复杂之处。

The above link is for dynamic select box. 上面的链接用于动态选择框。 I want to do the same thing in multiselect. 我想在多选中做同样的事情。

You can use disable when in ngOptions to disable, and filter to remove items: 您可以在ngOptions使用disable when来禁用和filter以删除项目:

 angular.module("app", []).controller('MainController', MainController); function MainController($scope) { vm = this; vm.optionsA = [1, 2, 3, 4]; vm.optionsB = [1, 2, 3, 4]; vm.optionsC = [1, 2, 3, 4]; vm.selectA = []; vm.selectB = []; vm.selectC = []; vm.disable = function(i) { return vm.selectA.indexOf(i) >= 0; } vm.filter = function(i) { return vm.selectA.indexOf(i) < 0; } } 
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script> <div ng-app="app" ng-controller="MainController as ctrl"> <select multiple ng-model="ctrl.selectA" ng-options="t for t in ctrl.optionsA"> </select> {{ctrl.selectA}} <select multiple ng-model="ctrl.selectB" ng-options="t disable when ctrl.disable(t) for t in ctrl.optionsB"> </select> {{ctrl.selectB}} <select multiple ng-model="ctrl.selectC" ng-options="t for t in ctrl.optionsC | filter:ctrl.filter"> </select> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM