从对象JS创建选择列表有多容易?
对象:
0: {UsersWork: "600", Name: "Salaria"},
1: {UsersWork: "700", Name: "Bavaria"}
我需要创建:
<select>
<option value="600">Salaria</option>
<option value="700">Bavaria</option>
</select>
我尝试使用ng-option
:
<option ng-show="specializationSelect == {{value.UsersSpecializationIdSpecialization}}" value="{{value.UsersWorkSpaceIdUser}}" ng-repeat="(key, value) in options">{{value.DetailToUsersName}}</option>
答案 0 :(得分:2)
使用ng-options
<select ng-options="person.UsersWork as person.Name for (objId, person) in persons"></select>
假设您的数据数组对象位于$scope.persons
中(无论如何都将其解析)
答案 1 :(得分:1)
$scope.options = {
"Blue": "color_1",
"Red": "color_2",
"Green": "color_3"
}
<select ng-model="selected"
ng-options="name for (name, value) in options">