gpt4 book ai didi

javascript - 如何从下拉列表中删除除从另一个下拉列表中选择的值之外的所有值

转载 作者:行者123 更新时间:2023-12-03 03:57:42 27 4
gpt4 key购买 nike

我有三个下拉菜单:-

    <select clas="col-md-3" ng-model="a.userList" ng-change="selectValues(a.userList)">
<option>AX</option>
<option>AF</option>
<option>AM</option>
<option>BX</option>
<option>BF</option>
<option>BM</option>
<option>CX</option>
<option>CF</option>
<option>CM</option>
<option>DX</option>
<option>DF</option>
<option>DM</option>
</select>
<select clas="col-md-3" ng-model="a.userCode">
<option>A</option>
<option>B</option>
<option>C</option>
<option>D</option>
</select>
<select clas="col-md-3" ng-model="a.userId">
<option>X</option>
<option>F</option>
<option>M</option>
</select>

我想要的是,当用户选择 AX 时,然后从其他两个下拉列表中分别选择 A 和 X,并从这两个下拉列表中删除所有其他值。

我的指令代码:-

               scope.selectValues = function(userList){
switch(userList){
case "AX" : scope.a.userCode = "A";
scope.a.userId = "X";
break;
case "AF" : scope.a.userCode = "A";
scope.a.userId = "F";
break;
case "AM" : scope.a.userCode = "A";
scope.a.userId = "M";
break;
};

};

在上面的代码中,我可以选择我想要选择的特定值,但无法从两个下拉列表中删除所有其他值。谁能告诉我如何从下拉列表中删除值。

最佳答案

你应该把你的选择放在范围内!

JS

scope.userList = ["AX","AF", "AM", "BX", "BF"];
//Obviously put all of your options in this array also for the other selects
scope.userCode = [....];
scope.userId = [....];

HTML

ng-options is what you need

 <select class="col-md-3" ng-model="a.userList"
ng-options="option for option in topUserList track by $index"
ng-change="selectValues(a.userList)"></select>

JS

 scope.selectValues = function(userList){
scope.a.userCode = userList.charAt(0);
scope.a.userId = userList.charAt(1);
scope.userCode = [scope.a.userCode];
scope.userId = [scope.a.userId];

};

关于javascript - 如何从下拉列表中删除除从另一个下拉列表中选择的值之外的所有值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44862472/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com