我有一个三重嵌套的ng-repeat,我正在使用一个简单的.splice来允许用户删除里面的项目。我可以发送最高级别项目的索引,$ parent。$ index下一级别,但是在第三级下来我需要像$ parent一样。$ parent。$ index传递正确项目的索引int他将json对象删除,我可以这样做吗?
这是我尝试过的事情
ng-click="deleteMe($parent.$parent.$index, $parent.$index, $index)
我怎样才能正确发送最高父母的索引?谢谢!
答案 0 :(得分:1)
使用ng-init请在此处查看更多https://docs.angularjs.org/api/ng/directive/ngInit
或示例演示http://plnkr.co/edit/qRJlAzPfwaZr8NENs7K0?p=preview
<body ng-controller="MainCtrl">
<div ng-repeat="father in data" ng-init="indxFirst = $index">
<h3>{{father.person}}</h3>
<ul>
<li ng-repeat="kids in father.kids" ng-init="indxSecond = $index">{{kids.name}}
<p ng-repeat="color in kids.colors" ng-init="indxThird=$index">Colour: {{color.color}}
<button ng-click="delete(indxFirst, indxSecond, indxThird)">delete</button>
<p>
</li>
</ul>
</div>
</body>