ng-options trackby in group expression

时间:2014-09-26 16:39:04

标签: javascript angularjs angularjs-ng-options

我在这里做错了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的值。

1 个答案:

答案 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>