You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在AngularJS的ng-repeat表格中关联遍历额外数组

解决方案:利用ng-repeat的$index关联数组

当然可以实现!你可以利用AngularJS ng-repeat自带的$index特殊变量来关联你的temp数组和allInfo的遍历项,具体做法很简单:

修改后的代码片段

<tbody ng-repeat="ts in allInfo">
  <td> {{ts.id}} </td>
  <td> {{ts.participant}} </td>
  <!-- 新增的列,通过$index匹配temp数组的对应元素 -->
  <td> {{temp[$index]}} </td>
</tbody>

原理说明

  • $index是ng-repeat内置的特殊变量,代表当前遍历项在allInfo数组中的索引(从0开始计数)。
  • 你的temp数组索引正好和allInfo的行索引一一对应:第一行$index=0对应temp[0]='1234',第二行$index=1对应temp[1]='1235',以此类推。

可选的边界处理

如果担心allInfo的长度大于temp的长度(导致后面的行显示undefined),可以添加一个默认值处理:

<td> {{temp[$index] || ''}} </td>

这样当temp中没有对应索引的元素时,会显示空字符串而不是undefined。

内容的提问来源于stack exchange,提问作者jamesfr

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 10:01:09