在 ngOptions 中设置键值 AngularJS
Set key value in ngOptions AngularJS
我正在尝试使用 ngOptions 创建一个 select 下拉菜单。我将如何从下面的数据中将城市名称列为 select 中的选项?
所以选项是:
<option>Perugia</option>
<option>New Brunswick</option>
<option>Vicenza</option>
{
Perugia: {
country: [
"IT"
]
},
New Brunswick: {
state: [
"NJ"
]
},
Vicenza: {
country: [
"IT"
]
}
}
我创建了一个fiddle,检查一下
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";
我正在尝试使用 ngOptions 创建一个 select 下拉菜单。我将如何从下面的数据中将城市名称列为 select 中的选项?
所以选项是:
<option>Perugia</option>
<option>New Brunswick</option>
<option>Vicenza</option>
{
Perugia: {
country: [
"IT"
]
},
New Brunswick: {
state: [
"NJ"
]
},
Vicenza: {
country: [
"IT"
]
}
}
我创建了一个fiddle,检查一下
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";