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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章