AngularJS的ng-repeat循环中如何获得被循环列表的索引值

使用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就可以了。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值