我有嵌套数组,所以我不得不使用3次ng-repeat
<div ng-repeat = "cat in cats" >
<div ng-repeat = "kitty in cat " >
<button ng-click="delete($index)">Delete</button>
</div>
</div>
</div>
所以我的问题是我无法访问第二次重复$ index,任何想法?
答案 0 :(得分:4)
这是ng-init指令
的目的<div ng-repeat="cat in cats" ng-init="catIndex = $index">
<div ng-repeat="kitty in cat">
<button ng-click="delete(catIndex)">Delete</button>
</div>
</div>
或者使用(index, value)
格式:
<div ng-repeat="(catIndex, cat) in cats">
<div ng-repeat="kitty in cat">
<button ng-click="delete(catIndex)">Delete</button>
</div>
</div>
答案 1 :(得分:-2)
<div ng-repeat = "cat in cats track by $catIndex" >
<div ng-repeat = "kitty in cat track by $kittyIndex " >
<button ng-click="delete($kittyIndex)">Delete</button>
</div>
</div>