gpt4 book ai didi

javascript - AngularJS 中 ng-repeat 解析的列表元素的唯一标识符

转载 作者:行者123 更新时间:2023-11-30 12:24:42 27 4
gpt4 key购买 nike

我需要重复变量“tab.excelFields”中的一些列表。我已经成功地做到了这一点,简单的 ng-repeat。代码如下所示:

<tr>
<th ng-repeat="field in tab.excelFields" class="btn btn-danger" style="display:table-cell;" id="{{id}}">{{field}}</th>
</tr>

注意 {{id}} 字段。我需要在此处输入唯一值...1、2、3 等等

问题:如何为我显示的每个字段添加唯一 ID?诸如“[1,2,3] 中的 id”之类的东西与我的代码结合使用。两个问题:-

  1. 如何在 ng-repeat< 中给“id in [1,2,3]”和“field in tab.excelFields”/?它可以带两个参数吗?

  2. 我的字段不限于任何固定数量。它可以是一或一千。如何动态创建计数器并将其添加到“id”字段?

最佳答案

在 ngRepeat 范围内使用 $index 变量。

<th ng-repeat="field in tab.excelFields" class="btn btn-danger" style="display:table-cell;" id="{{$index}}">{{field}}</th>

关于javascript - AngularJS 中 ng-repeat 解析的列表元素的唯一标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29842469/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com