首页 > 代码库 > 如何在深层嵌套ngRepeat中获取不同层级的$index

如何在深层嵌套ngRepeat中获取不同层级的$index

<ul class="list-group" ng-repeat="item in vm.appData" ng-init="outerIndex = $index">
                    <h3>{{item.name}}<span class="outer-index">outerIndex:{{outerIndex}}</span></h3>
                    <h4>{{item.author}}</h4>
                    <li class="list-group-item">
                        <ul class="list-group">
                            <li class="list-group-item" ng-repeat="v in item.books track by $index" ng-init="innerIndex = $index">
                                {{v.name}} <span class="inner-index">innerIndex:{{innerIndex}}</span><button class="btn btn-danger" ng-click="vm.removeItem(outerIndex, innerIndex)">删除</button>
                            </li>
                            <li class="list-group-item">
                                <form class="form-inline">
                                    <input class="form-control" ng-model="vm.tempItem[$index]" type="text">
                                    <button class="btn btn-primary" ng-click="vm.addItem(outerIndex)">添加一项</button>
                                </form>
                            </li>
                        </ul>

                    </li>
                    <hr ng-show="!$last">
                </ul>

 

如何在深层嵌套ngRepeat中获取不同层级的$index