ng-repeat获取父级INDEX
2014年10月11日 · 40 字 · 1 分钟
angularjs的循环嵌套我就不多说了,无非是ng-repeat的嵌套而已,如果需要获取索引请使用$index。 那么问题来了,$index只能获取当前循环的索引,如果需要获取父级的索引怎么办? 原理其实也不难,在父级ng-repeat时利用ng-init写入一个变量即可,子循环是可以访问到的。 <div ng-controller="MainCtrl"> <dl ng-repeat="user in users"> <dt ng-init="p_index=$index">Name:</dt> <dd ng-repeat="p in user.