下拉列表中生成错误的值

时间:2014-04-29 10:01:55

标签: angularjs

html代码

<select id="userGroups" name="userGroups" ng-model="userGroups" 
    ng-init="userGroups = userGroups || groups[0].groupId"
    ng-options="grp.groupId as grp.groupName for grp in groups" class="form-control"></select>

但生成的选项就像这样

<option value="0" selected="selected">admins</option>
<option value="1">user</option>

它必须是这样的,因为admin的id为1而用户的id为2

<option value="1" selected="selected">admins</option>
<option value="2">user</option>

这是团体的json,我通过{{ groups | json }}

[
  {
    "groupId": 1,
    "groupName": "admins"
  },
  {
    "groupId": 2,
    "groupName": "users"
  }
]

0 个答案:

没有答案