0

我有一个表格,每列上方都有一个下拉列表,其中列数是动态的。我创建了这个如下

            <table class='table' >
                <tr>
                    <th ng-repeat= "item in importTable[0]">
                        <select ng-model="selectedItem" ng-options="i.Name for i in optionList"></select>
                    </th>
                </tr>
                <tr ng-repeat="row in importTable">
                    <td ng-repeat="item in row">{{ item }} </td>
                </tr>
            </table>

其中 optionList 是下拉列表中的选项列表。所有的下拉菜单都有相同的选项列表。

如何将所选项目及其上方列的索引添加到模型的范围?

这是 JSfiddle http://jsfiddle.net/U3pVM/769/的链接,只需单击导入。我希望能够定义哪一列是哪一类型。

4

1 回答 1

1

您可以使用 ngRepeat 提供的 $index 变量将ngModel设置为数组中的特定项目:

在您的控制器中,您首先定义将包含所有模型的数组:

function ImportCtrl($scope) {   
  $scope.selectedItems = [];
  ...
}

而且,在 ngRepeat 中,您将 ngModel 引用到selectedItems数组中的特定项目:

<select ng-model="selectedItems[$index]" ng-options="i.Name for i in columnNames"></select>

演示小提琴

于 2013-06-19T05:02:28.110 回答