0

希望有人可以帮助应对这一挑战。

我在两个构建单独的下拉列表中使用了 1 个机场阵列。

<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 个用于目的地),只是不知道如何处理它。

谢谢!

4

1 回答 1

0

使用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);

}
于 2015-02-13T03:45:33.623 回答