0

我无法使用 ng-options 指令将选项元素添加到选择元素。但是我可以使用 ng-repeat 指令来做到这一点。为什么?

HTML,

<div ng-app ng-controller="DescAttrCtrl">
   <div ng-repeat="dattr in dattrs">
        <div ng-repeat="v in dattr.values">
            {{v | json}}
        </div>
        <select name="dattr-{{$index}}" ng-options="v for v in dattr.values">
                <option value=""> --- select a value --- </option>
         <!--   <option ng-repeat="v in dattr.values">{{v}}</option> -->
        </select>
    </div>
</div>

Javascript,

function DescAttrCtrl($scope) {
     $scope.dattrs = [
     {
          "name" : "first attribute",
          "description" : "attribute first description",
          "values" : ["value1", "value2", "value3", "value4"]
     },
     {
          "name" : "second attribute",
          "description" : "attribute second description",
          "values" : ["value1", "value2", "value3", "value4"]
     }
    ];
}

小提琴,http://jsfiddle.net/FwVbC/

4

1 回答 1

5

请修改代码如下

<select ng-model="selection" ng-options="values for values in dattr.values">
   </select>
于 2013-03-20T07:35:52.787 回答