AngularJS 中 ng-repeat 解析的列表元素的唯一标识符
Unique Identifier For Elements of a List Parsed By ng-repeat in AngularJS
我需要重复变量“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? "id in [1,2,3]" 之类的东西与我的代码结合使用。两个问题:-
如何在ng-repeat
中给“id in [1,2,3]
”加上“field in tab.excelFields
”?它可以带两个参数吗?
我的字段不限于任何固定数字。它可以是一或一千。如何动态创建一个计数器并添加到“id
”字段?
在 ngRepeat 范围内使用 $index
变量。
<th ng-repeat="field in tab.excelFields" class="btn btn-danger" style="display:table-cell;" id="{{$index}}">{{field}}</th>
我需要重复变量“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? "id in [1,2,3]" 之类的东西与我的代码结合使用。两个问题:-
如何在
ng-repeat
中给“id in [1,2,3]
”加上“field in tab.excelFields
”?它可以带两个参数吗?我的字段不限于任何固定数字。它可以是一或一千。如何动态创建一个计数器并添加到“
id
”字段?
在 ngRepeat 范围内使用 $index
变量。
<th ng-repeat="field in tab.excelFields" class="btn btn-danger" style="display:table-cell;" id="{{$index}}">{{field}}</th>