我需要为渲染的选择标记设置选项值yo id,使用以下示例我可以将选项值设置为0,1,2。
知道我在这里做错了什么吗?
function ctrl($scope) {
$scope.devices = [{
name: "pc1",
id: 10
}, {
name: "pc2",
id: 20
}, {
name: "pc3",
id: 30
}];
$scope.selectedDevice = $scope.devices[0];
}
<div ng-app ng-controller="ctrl">
<select data-ng-model="selectedDevice" name="devices" data-ng-required="true" data-ng-options="device.name for device in devices"></select>
</div>
答案 0 :(得分:1)
<select data-ng-model="selectedDevice"
name="devices"
data-ng-required="true"
data-ng-options="device.id as device.name for device in devices">
</select>
$scope.selectedDevice = $scope.devices[0].id;
更新了 Fiddle