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 に答える