简体   繁体   English

为什么要通过ng-click触发嵌套ng-repeat内的$ index跟踪

[英]Why track by $index is necessary for ng-click to trigger inside nested ng-repeat

I was using ng-click inside the nested ng-repeat but found that the inner most ng-click(3rd level) was not getting triggered. 我在嵌套的ng-repeat内使用ng-click ,但发现最里面的ng-click(3rd level)没有被触发。 But when I used track by $index for the inner most ng-repeat, ng-click got triggered. 但是,当我使用track by $index最里面的ng-repeat时,就会触发ng-click。 I am not able to understand this behavior of nested ng-repeat. 我无法理解嵌套ng-repeat的这种行为。

Please find below the code snippet 请在下面的代码段中找到

<ul class="a">
    <li class="b" ng-repeat="items in Objects track by $index" ng-click="callSomething()">
        <a>{{items.name}}</a>
        <ul class="c">
            <li class="d" ng-repeat="items1 in Objects1 track by $index" ng-click="callSomething()">
                <a>{{items1.name}}</a>
                <ul class="e">
                    <li class="f" ng-repeat="items2 in Objects3 track by $index" ng-click="callSomething()">
                        <a>{{items3.name}}</a>
                    </li>
                </ul>
            </li>
        </ul>
    </li>
</ul>

Its really related to ng-repeat behavior. 它确实与ng-repeat行为有关。 Each element is tracked uniquely and mapped to the scope. 每个元素都进行唯一跟踪并映射到范围。 I think this thread already answers your questions: 我认为该线程已经回答了您的问题:

How does ng-repeat work? ng-repeat如何工作?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM