我有三个下拉菜单: -
<select clas="col-md-3" ng-model="a.userList"
ng-options="p as p.users for p in List"
ng-change="selectValues(a.userList)">
<option value="">Select</option>
</select>
<select clas="col-md-3" ng-model="a.userCode" id="dropdown1">
<option>A</option>
<option>B</option>
<option>C</option>
<option>D</option>
</select>
<select clas="col-md-3" ng-model="a.userId" id="dropdown2">
<option>X</option>
<option>F</option>
<option>M</option>
</select>
我想要的是当用户选择AX
然后从其他两个下拉列表中分别选择A和X,并从这两个下拉列表中删除所有其他值。
我的指令代码: -
(function () {
'use strict';
angular.module('myApp.components')
.directive('user', user);
user.$inject = ['$http', '$timeout', 'ApiServices'];
function user($http, $timeout, ApiServices) {
return {
restrict: 'EA',
scope: {
},
link: function (scope, el, attrs) {
scope.a = {};
$('#user').on('hide.bs.modal', function () {
scope.a = {};
});
$('#user').on('shown.bs.modal', function () {
scope.getAllUserList = function(){
scope.List = [];
ApiServices.getAllUserList().then(function (response) {
scope.List = response.data;
});
}
scope.getAllUserList();
});
scope.selectValues = function(userList){
switch(userList){
case "user1" : scope.a.userCode = "A";
$('dropdown1').find('option[value!="'+scope.a.userCode+'"]').remove();
scope.a.userCode = "X";
$('dropdown2').find('option[value!="'+scope.a.userId+'"]').remove();
break;
case "user1" : scope.a.userCode = "B";
$('dropdown1').find('option[value!="'+scope.a.userCode+'"]').remove();
scope.mlmScrip.segment = "X";
$('dropdown2').find('option[value!="'+scope.a.userId+'"]').remove();
break;
case "user1" : scope.a.userCode = "C";
$('dropdown1').find('option[value!="'+scope.a.userCode+'"]').remove();
scope.mlmScrip.segment = "X";
$('dropdown2').find('option[value!="'+scope.a.userId+'"]').remove();
break;
//and so on
}
}
//Link function ends below
},
templateUrl: 'js/components/folder/info.html'
};
}
})();
在上面的代码中,我能够选择我想要选择的特定值,但是无法从两个下拉列表中删除所有其他值。我的jquery代码无效。我知道代码是正确的,但我认为我把它弄错了。任何人都可以指出错误。