Javascript 如何使用angularJs中的lodash从其他下拉列表中删除选定的下拉列表值
我有四个下拉列表:-Javascript 如何使用angularJs中的lodash从其他下拉列表中删除选定的下拉列表值,javascript,angularjs,Javascript,Angularjs,我有四个下拉列表:- <div><label>Priority:</label> <label>First</label> <select ng-model="a.priority[0]" ng-change="selectPriority(a.priority[0])" data-ng-options="x for x in priorityArray"> <o
<div><label>Priority:</label>
<label>First</label>
<select ng-model="a.priority[0]" ng-change="selectPriority(a.priority[0])" data-ng-options="x for x in priorityArray">
<option value="{{x}}"></option>
</select>
<label>Second</label>
<select ng-model="a.priority[1]" ng-change="selectPriority(a.priority[1])" data-ng-options="x for x in priorityArray" >
<option value="{{x}}"></option>
</select>
<label>Third</label>
<select ng-model="a.priority[2]" ng-change="selectPriority(a.priority[2])" data-ng-options="x for x in priorityArray">
<option value="{{x}}"></option>
</select>
<label>Fourth</label>
<select ng-model="a.priority[3]" ng-change="selectPriority(a.priority[3])" data-ng-options="x for x in priorityArray">
<option value="{{x}}"></option>
</select>
</div>
我使用lodash过滤器在其他下拉列表中获取过滤后的数组。使用当前解决方案,所选值也会过滤原始下拉列表(我从中选择了优先级)。我希望选定的值保留在原始下拉列表中。为每个下拉列表保留不同的数组不是一个有效的解决方案。有人能为我推荐一些其他的解决方案吗?在哪里使用产品指令?在我的index.htmlc中,你能尝试使用过滤器,看看是否有效吗
(function () {
'use strict';
angular.module('myApp.components')
.directive('product', product);
product.$inject = ['$http', '$timeout'];
function product($http, $timeout) {
return {
restrict: 'EA',
scope: {},
link: function (scope, el, attrs) {
scope.a = {};
scope.priorityArray = ["ONE","TWO","THREE","FOUR"];
$('#product').on('hide.bs.modal', function () {
scope.a = {};
});
$('#product').on('shown.bs.modal', function () {
scope.selectPriority = function (priority) {
scope.selectedPriority = [];
scope.selectedPriority.push(priority);
scope.priorityArray = _.difference(scope.priorityArray, scope.selectedPriority);
}
},
templateUrl: 'js/components/product.html'
};
}
})();