我正在尝试使用ngOptions创建选择下拉列表。如何从下面的数据中选择将城市名称列为选项?
所以选项是:
<option>Perugia</option>
<option>New Brunswick</option>
<option>Vicenza</option>
{
Perugia: {
country: [
"IT"
]
},
New Brunswick: {
state: [
"NJ"
]
},
Vicenza: {
country: [
"IT"
]
}
}
答案 0 :(得分:2)
我创造了一个小提琴,检查它
https://jsbin.com/jarepo/edit?html,js,output
<select name="mySelect" id="mySelect"
ng-options="name as name for (name, obj) in cities"
ng-model="selected">
JS,
$scope.cities = {
Perugia: {
country: [
"IT"
]
},
'New Brunswick': {
state: [
"NJ"
]
},
Vicenza: {
country: [
"IT"
]
}
};
$scope.selected = "Perugia";