2 multiple select and single option list

馋奶兔 提交于 2020-01-14 06:33:06

问题


I have 2 multi select element and both get options from a variable list. If a variable selected as row variable it will not be shown in column select options. if user unselect option then variable should will shown in both list

$scope.variables = ['a','b','c','d','e','f'];

<select multiple ng-model="selectedAsRows" ng-options="v for v in variables"></select>
<select multiple ng-model="selectedAsCols" ng-options="v for v in variables"></select>

回答1:


I think that I understood what you want. Here is a fiddle with an example:

http://jsfiddle.net/26fZb/209/

The key is to use a custom filter like this one:

filter: { name: '!' + selectedAsFriend.name }

EDIT:

Here is your case with multiSelect. I have created custom filters.

app.filter('myFilter', function() {
  return function(inputList, list) {
     return inputList.filter(isAlreadySelected(list));
};

  function isAlreadySelected(list){
    return function(elem){
      if (list.indexOf(elem) == -1) 
        return true;
      else
        return false;
    }
  }

});

Then to use it in the html file:

<select multiple ng-model="selectedAsRows" ng-options="v for v in variables | myFilter: selectedAsCols"></select>
<select multiple   ng-model="selectedAsCols" ng-options="v for v in variables | myFilter: selectedAsRows"></select>

Take a look at the full code:

http://plnkr.co/edit/6eWZB75dAdquPD1jMmb7?p=preview



来源:https://stackoverflow.com/questions/33236247/2-multiple-select-and-single-option-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!