Try using the comprehension expression for objects:
ng-options="user as user.name for (key,user) in users"
题
I have a select dropdown I'd like to populate with the names of users in objects:
<select id="entityDropDown"
ng-model="selectedUser"
ng-options="user as user.name for user in users"
ng-change="getUserInfo(selectedUser)">
</select>
My object is structured as such:
users: {
1: {
name: Demo Administrator,
id: 1,
domain: null,
email: null,
isAdmin: False,
},
4: {
name: ITUN\WSS,
id: 4,
domain: i:0#.f|admembers|,
email: ,
isAdmin: False,
}
}
解决方案
Try using the comprehension expression for objects:
ng-options="user as user.name for (key,user) in users"
其他提示
In your case users
is not an array.
So instead of
users: {
1: {
name: Demo Administrator
id: 1
domain: ITUN\demoadmin_compulite
email: simkessy@gmail.com
isAdmin: False
}
}
You want something like this
users: [
{
name: Demo Administrator
id: 1
domain: ITUN\demoadmin_compulite
email: simkessy@gmail.com
isAdmin: False
} ,
{
name: Demo Administrator
id: 2
domain: ITUN\demoadmin_compulite
email: simkessy@gmail.com
isAdmin: False
}
]