[英]AngularJS nested ng-repeat access to Index
I have nested array so I had to use 3 times ng-repeat 我有嵌套数组,所以我不得不使用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>
So my problem is that I can't get access to 2nd ng-repeat $index , any ideas ? 所以我的问题是我无法访问2nd ng-repeat $ index,有什么主意吗?
This is the purpose of the ng-init directive 这是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>
Alternatively use (index, value)
formatting: 或者使用
(index, value)
格式:
<div ng-repeat="(catIndex, cat) in cats">
<div ng-repeat="kitty in cat">
<button ng-click="delete(catIndex)">Delete</button>
</div>
</div>
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.