我在这里做错了Angular(1.1.5)没有在这个分组选择下拉列表中正确选择正确的值?
HTML:<select ng-model="options.metricId" ng-options="answer.id as answer.name group by answer.question for answer in options.answers track by answer.id"></select>
options.metricId
由控制器正确设置。
options.answers
对象如下所示:
{id: 8, name: "Leads Others", question: "Assessment"}
所有选项都出现了,但它没有像我期望的那样选择answer.id == options.metricId
的值。
答案 0 :(得分:0)
将parseInt(answer.id)
添加到轨道表达式解决了这个问题。
<select class="form-control" ng-model="options.metricId" ng-options="answer.id as answer.name group by answer.question for answer in options.answers track by parseInt(answer.id)" ng-change="events.updateMetrics()"></select>