0

我有一个这样的对象列表:

 $scope.list =  [ { id : 1, value : "one"}, 
                  { id : 2, value : "two"},
                  { id : 3, value : "three"} ];

我希望它输出这样的列表:

 <select>
     <option value="1">one</option>
     <option value="2">two</option>
     <option value="3">three</option>
  </select>

执行此操作所需的 ng-options 语法是什么?

4

2 回答 2

1

你可以试试这个;

<select name="yourname" ng-options="option.id as option.value for option in list"></select>
于 2013-10-23T03:59:50.230 回答
1

HTML

<div ng-controller = "fessCntrl"> 
 <select ng-model="selectedItem" ng-options="selectedItem as selectedItem.value for selectedItem in list" ></select>   
</div>

JS

 $scope.list =  [ { id : 1, value : "one"}, 
              { id : 2, value : "two"},
              { id : 3, value : "three"} ];
 // select 1st by default
 $scope.selectedItem = $scope.list[0];

演示Fiddle

于 2013-10-23T05:19:14.973 回答