如何从OptGroup访问ng-repeat值

时间:2015-07-27 07:51:47

标签: arrays angularjs angularjs-ng-repeat

这是我的HTML代码

<select id="drplist" ng-model="node.field.name" data-nodrag class="form-control" ng-change="currentColumnInfo(node.field.name,Item.Type,formname)">
                    <optgroup label="{{primaryObjectName}}">
                        <option ng-repeat="Item in columnsList" value="{{Item.name}}" id="{{Item.name}}" ng-selected="true">{{Item.name}}</option>
                    </optgroup>
                    <optgroup label="{{object.formName}}" ng-repeat="object in secondaryObjectList">
                        <option ng-repeat="Item in object.fields" value="{{Item.name}}" id="{{Item.name}}">{{Item.name}}</option>

                    </optgroup>
                </select>

当此ng-change函数node.field.name触发时,我item.Typeformnameundefinedng-change="currentColumnInfo(node.field.name,Item.Type,formname)";有人可以帮助我吗?

1 个答案:

答案 0 :(得分:2)

您无法在Item循环之外引用ng-repeat

我认为您需要做的是将columnsListobject.fields的数据结构转换为一个数据结构,并将label group by group for (key, value) in object表达式用于ng-options