使用angularJS框架的话都需要引入angular.min.js文件,这个想必各位大佬都懂得,我就不多说了。
这里主要说说AngularJS的ng-repeat循环中如何获得被循环列表的索引值。
假如有一个表格:
代码如下:
<table class="table table-bordered table-striped table-hover dataTable">
<thead>
<tr>
<th class="sorting">规格选项</th>
<th class="sorting">排序</th>
<th class="sorting">操作</th>
</thead>
<tbody>
<tr ng-repeat="pojo in entity.specificationOptionList">
<td>
<input class="form-control" placeholder="规格选项" ng-model="pojo.optionName">
</td>
<td>
<input class="form-control" placeholder="排序" ng-model="pojo.orders">
</td>
<td>
<button type="button" class="btn btn-default" title="删除" ng-click="deleteTableRow($index)"><i class="fa fa-trash-o"></i> 删除</button>
</td>
</tr>
</tbody>
</table>
我点击删除按钮,就相当于把specificationOptionList集合去除一列数据,调用controller.js文件中调用$scope.entity.specificationOptionList.splice(index,1)。
那index的值从何得到呢,我们只需要在ng-repeat循环中,删除按钮中的ng-click="deleteTableRow()方法里传入$index就可以了。