根据一些JSON数据,我得到N个“选择”组件,“选项”由外部API填充。 我需要的是,当一个选项选择在一个“选择”组件中,它不应该显示在其他组件中,我试图应用自定义过滤器,但我还没有运气。Angularjs - 从其他<select>组件中筛选选定的选项
.filter('exclude',function(lodash) {
//@param itemsArray: array of items
//which fills the options of the select component.
//@param selectedItem: the selected <option>
//from one of the <select> components.
return function(itemsArray, selectedItem) {
var output = itemsArray,
filteredItemsArray = [];
if(selectedItem) {
var idx = lodash.findKey(itemsArray, { name: selectedItem.name });
filteredItemsArray.push(selectedItem[idx]);
output.splice(idx, 1);
}
return output;
}
});
这应该是在HTML中的行为:
<select ng-option="p in publi track by $index | exclude: pSelect[$Index])" ng-model="pSelect[$Index]">
<option val="usa" selected>USA</option>
<option val="arg">Argentina</option>
<option val="col">Colombia</option>
<option val="cnd">Canada</option>
<select>
<select ng-option="p in publi track by $index | exclude: pSelect[$Index])" ng-model="pSelect[$Index]">
<option val="arg" selected>Argentina</option>
<option val="col">Colombia</option>
<option val="cnd">Canada</option>
<select>
<select ng-option="p in publi track by $index | exclude: pSelect[$Index])" ng-model="pSelect[$Index]">
<option val="col" selected>Colombia</option>
<option val="cnd">Canada</option>
<select>
我试过,但这个只是从阵列中删除的项目,它从来没有得到选择。
我该怎么办?
请表明了这是如何正在执行... [MCVE] – charlietfl
我预期的行为进行更新。 @charlietfl –