我有一个下拉列表,它由三个记录器d1,d2,d3正确填充,它们的值为0,1,2
<div class="form-group">
<label for="Distance" class="col-md-3">
Distance :
</label>
<div class="col-md-4">
<select id="Distance" name="Distance" class="form-control selectwidthauto" ng-model="ModelData.Distance"
ng-options="distance.Code as distance.Description for distance in DropdownData.Distances">
</select>
</div>
</div>
为什么下拉选择不起作用,而我在html上将{{ModelData.Distance}}的值设为2。
答案 0 :(得分:1)
您可以使用indexOf检查迭代次数。这将帮助您识别所选的特定迭代。
<div ng-app ng-controller="app">
<select
ng-model="item"
ng-options="values.indexOf(item) as item for item in values"></select>
item: {{item}}
</div>
function app($scope) {
$scope.values = ["Value1","Value2"];
$scope.item= 0;
}