我写了下面的代码
<select ng-model="selectedseasId" ng-options="seas.seasInternalId as seas.seasName for seas in seass track by seas.seasInternalId"> </select>
$scope.selectedseasId = 3;
我有类似的数据
var seass = [ {
"seasInternalId" : 4,
"seasName": "My Second seas"
},
{
"seasInternalId" : 3,
"seasName": "My Second seas"
}
];
在选择框中没有选择任何值。我的代码有什么问题吗?
最佳答案
ng-options跟踪和选择不兼容。看到这个link
当然,您不需要按ID进行跟踪,因为我认为seasInternalId是唯一的,因此seas.seasInternalId as seas.seasName for seas in seass
就足够了并且可以工作。