在 ng-repeat 中遍历数组

Iterate through an array in an ng-repeat

现在我有一个数组。 IE。 var temp = ['1234', '1235', '1236'];

我的 html 已经遍历了一个 JSON 对象,但我想在刚刚遍历数组的 table 中添加一列。例如,我设置了一个临时列,第一行的值应该是 1234,第二行的值应该是 1235,最后一行的值应该是 1236。有没有办法用 ng-repeat 做到这一点?

<tbody ng-repeat="ts in allInfo">
                                <td>
                                    {{ts.id}}
                                </td>
                                <td>
                                    {{ts.participant}}
                                </td>
                                <td>
                                    {{temp}} <-- each row should be the next value in the array.  Right now it outputs the whole array.
                                </td>
                                <td class="text-capitalize">
                                    {{ts.action}}
                                </td>
                    </tbody>

假设您的数组具有与您正在迭代的对象相同数量的元素,您可以使用 ng-repeat 的 $index 变量来保存当前迭代值。

如果您的对象可能有重复的条目,您可能还想在 ng-repeat 语句中使用 track by

<tbody ng-repeat="ts in allInfo track by $index">
  <tr>
    <td>
       {{ts.id}}
    </td>
    <td>
      {{ts.participant}}
    </td>
    <td>
      {{temp[$index]}} 
    </td>
    <td class="text-capitalize">
      {{ts.action}}
    </td>
  </tr>
</tbody>