角度ng-repeat访问下一个项目

时间:2014-10-27 19:15:40

标签: angularjs angularjs-ng-repeat

我想在ng-repeat指令中引用下一个元素吗?

 <li ng-repeat="row in rows">
      if {{row.someValue}} === {{row+1.someValue}}
      //Is it poss to check if the following row so I can do some kind of conditional comparison ?
 </li>

由于 w ^

1 个答案:

答案 0 :(得分:0)

正如@PSL所说 - 你只需要在循环的数组中获取下一个索引:

 <li ng-repeat="row in rows">
          {{rows[$index+1]}} // this will give you the next row's data
    <div ng-switch on="rows[$index+1].value">
        <div ng-switch-when="true">
            <!-- shows when the value of the next row is true-->
        </div>
    <div ng-switch-when="false">
            <!-- shows when the value of the next row is false-->
        </div>
    </div>   
 </li>