繁体   English   中英

如何在ng-repeat嵌套循环中重置$ index的值?

[英]How to reset the value of $index in ng-repeat nested loops?

我有这段代码,但不确定实现它的方式是对还是错。 但到目前为止,在我看来,绝对没有用。

<div ng-repeat="data in DataObject">
    <ul style="list-style-type:decimal !important;">
        <li ng-repeat="(indexX,answer) in bkm.content_detail.question_data.question_content[0].question_answer[0].answer_text track by $index">
            {{indexX+1}} - {{answer | joinBy : " / "}}
        </li>
        <div ng-init="indexX=0"></div>
    </ul>
</div>

好吧,我试图让价值indexX=0ng-init="indexX=0" 我做的方式真的吗?

我需要重设indexX是因为外部div的ng-repeat嵌套循环。

您可以在ng-repeat循环中添加一个指令,该指令可以利用scope。$ last参数来重置最后一个元素的索引。

示例: https//stackoverflow.com/a/13472605/6452040

暂无
暂无

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

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