我正在尝试将值绑定到下拉列表,我的数据是一个Object数组,但无法找到将选择的id绑定到下拉列表的方法。
这是我的代码和小提琴
var app = angular.module('myApp', []);
function Ctrl($scope) {
$scope.optionSource = [{
"name" : "First Cost",
"id" : "1"
}, {
"name" : "Second",
"id" : "3"
}, {
"name" : "Third",
"id" : "2"
}, {
"name" : "Sone",
"id" : "5"
}, {
"name" : "List CC",
"id" : "4"
}];
$scope.value = [2,4];
}
HTML
<select multiple="multiple" ng-model="value"
ng-options="option.name for option in optionSource">
</select>
我想将id作为值。
感谢
答案 0 :(得分:4)
使用as
指定值。
<select multiple="multiple" ng-model="value"
ng-options="option.id as option.name for option in optionSource">
</select>