Angularjs 双重循环获取父级下标$index

来源:互联网 发布:linux pipe 编辑:程序博客网 时间:2024/06/09 16:36
Html代码  收藏代码
  1. <table class="table table-bordered">  
  2.         <tr ng-repeat="info in ttzInfo" ng-cloak>  
  3.           <td class="col-xs-2 adjust-col-2 text-right title-desc" ng-bind="info.title"></td>  
  4.           <td class="col-xs-3 adjust-col-3 text-center" ng-repeat="key in ['ttz', 'yeb', 'bank']">  
  5.             <span ng-if="info[key]">  
  6.               <span ng-if="info[key].length" ng-bind="info[key]" ng-class="{'year-interest': $parent.$parent.$parent.$first}"></span>  
  7.               <span ng-if="!info[key].length" class="glyphicon glyphicon-ok"></span>  
  8.             </span>  
  9.             <span ng-if="!info[key]" class="glyphicon glyphicon-remove"></span>  
  10.           </td>  
  11.         </tr>  
  12.       </table>  

 

 

直接获取父级下标,只有两个ng-repate写在一起的时候,使用 $parent.$index即可获取,若没多一级ng-if之类的判断条件,则接着在往上一级寻找即可。

其他ng-repate的函数都是同一个道理。

Angularjs在线教程:

http://each.sinaapp.com/angular/tutorial/ng-repeat.html

 

Variable Type Details$indexnumberiterator offset of the repeated element (0..length-1)$firstbooleantrue if the repeated element is first in the iterator.$middlebooleantrue if the repeated element is between the first and last in the iterator.$lastbooleantrue if the repeated element is last in the iterator.$evenbooleantrue if the iterator position $index is even (otherwise false).$oddbooleantrue if the iterator position $index is odd (otherwise false).转自:http://qiaolevip.iteye.com/blog/2242113