我在选择框中有位置列表。在选择位置时,相应的事件类型应显示在另一个选择框中。
$scope.locationNames=[
{id:"Onboard",value:"On-board service"},
{id:"Clubhouse",value:"Clubhouse"},
{id:"Gate",value:"Gate"}
];
$scope.incidentTypesList={
Onboard:[
{id:"IFE faulty",value:"IFE faulty"},
{id:"223",value:"No special meal as ordered"},
{id:"Spoilt",value:"Spoilt/damaged belongings"}
];
Clubhouse:[
{id:"",value"No appointments available"},
{id:"",value="Late/delayed transport service"},
{id:"",value="Facilities not available"}
];
};
我可以使用以下代码在列表中获取位置名称。
<select class="firstDropDown" ng-model="location" ng-options="item.id as item.value for item in locationNames">
<option value="">Select location</option>
</select>
您能否帮我解决如何选择此选项以在另一个选择框中显示值。
答案 0 :(得分:4)
我认为以下解决方案符合您的需求。您的阵列中存在一些需要修复的语法错误。
<强> HTML 强>
<div ng-app="myApp" ng-controller="myAppCtrl">
<select class="firstDropDown" ng-model="location" ng-options="item.id as item.value for item in locationNames">
<option value="">Select location</option>
</select>
<select class="secondDropDown" ng-model="incident" ng-options="incident.id as incident.value for incident in incidentTypesList[location]">
<option value="">Select incident</option>
</select>
</div>
JS
var myApp = angular.module("myApp", [])
myApp.controller("myAppCtrl", function($scope){
$scope.locationNames=[
{id:"Onboard",value:"On-board service"},
{id:"Clubhouse",value:"Clubhouse"},
{id:"Gate",value:"Gate"}
];
$scope.incidentTypesList={
Onboard:[
{id:"IFE faulty",value:"IFE faulty"},
{id:"223",value:"No special meal as ordered"},
{id:"Spoilt",value:"Spoilt/damaged belongings"}
],
Clubhouse:[
{id:"",value:"No appointments available"},
{id:"",value:"Late/delayed transport service"},
{id:"",value:"Facilities not available"}
]
}
});