使用AngularJS中的ngOptions隐藏其他列表中的选定选项
Hide selected option in other list using ngOptions in AngularJS
希望有人能帮助应对这一挑战。
我有一个阵列的机场正在使用两个单独的建设下降。
<select data-ng-model="flightData.origin" data-ng-options="airport.code as airport.label for airport in flightData.airports" name="origin"></select>
和
<select data-ng-model="flightData.destination" data-ng-options="airport.code as airport.label for airport in flightData.airports" name="destination"></select>
这两个列表显然有相同的选项。我想做的是,例如,当您在原点中选择"Sydney"
时,从目标下拉列表中删除"Sydney"
。
作为参考,这是机场数据的一个例子。
this.airports = [{
code: "TSV",
label: "Townsville",
}, {
code: "PER",
label: "Perth",
}, {
code: "BNE",
label: "Brisbane",
}, {
code: "MEL",
label: "Melbourne",
}, {
code: "KGI",
label: "Kalgoorlie",
}, {
code: "SYD",
label: "Sydney",
},{
code: "LAX",
label: "Los Angeles",
}, {
code: "JFK",
label: "New York",
}, {
code: "DEL",
label: "New Dehli",
}];
我知道我很可能需要两个单独的数组(1个用于原点,1个用于目的地),只是不知道如何处理它
谢谢!
使用ng-change
,还需要两个列表。
<select data-ng-model="flightData.airports_origin" ng-change="changeOrigin()" data-ng-options="airport.code as airport.label for airport in flightData.airports" name="origin"></select>
<select data-ng-model="flightData.airports_destination" data-ng-options="airport.code as airport.label for airport in flightData.airports" name="origin"></select>
在控制器中,注入filterFilter
,然后在可用目的地机场列表中搜索所选机场并将其删除。
// in your controller
$scope.airports_origin = angular.copy(this.airport);
$scope.airports_destination = angular.copy(this.airport);
$scope.changeOrigin = function(){
var selected_origin = flightData.origin;
var destination_airport = filterFilter(this.airports_destination,{'code':selected_origin.code})[0];
$scope.airports_destination.splice($scope.airports_destination.indexOf(destination_airport),1);
}
相关文章:
- 使用js将动态内容添加到选择选项列表中
- 如何使用jQuery隐藏与选择选项相关的选择选项列表
- 从ng选项列表中预选选项
- 正在从开发人员工具中的select元素打印选项列表
- HTML选择:将默认值设置为给定值,而不是从选项列表中选择
- 将过滤器添加到Angular中的选择框选项列表中
- 保留选项列表以供选择
- 在节点中实现依赖选项列表.js + express
- 在视觉效果页面中禁用从属选项列表
- 使用表排序器筛选所选选项列表中的选定项目
- jQuery 在选项列表中重新填充所选项目
- 使用 JavaScript 创建巨大的选项列表与以标记形式交付它们
- 使用 jQuery 或 Javascript 自动更新选择选项列表
- 如何在 JSHint 中设置选项列表
- Jquery函数将选项列表拆分为分层选择
- 重建选项列表时失去选择选项的焦点
- 使用javascript的表单中的两个下拉选项列表
- 如何在 Javascript 中删除多选选项列表中的重复值
- jQuery Mobile,在选项列表中选择所有项目
- 如何使ng选择's选项列表用当前的“;选择“;属性