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

使用ng-repeat与$index遍历对象数组渲染表格时最后一列不显示

Fixing the Missing Parameters Column in Your Angular Table

Hey there! Let's get that third column showing your parameters array properly. The issue comes down to how you're accessing your data in the ng-repeat and not properly iterating over the parameters array for each row.

What Was Wrong in Your Original Code

Your current ng-repeat uses rows in $ctrl.name (which doesn't match your actual data structure) and you're trying to access properties via $ctrl.name[$index]—this is misaligned with your myArray which contains objects with name, id, and parameters properties. Also, the third column wasn't set up to loop through the parameters array.

Corrected Code Example

Here's the fixed version that will render all three columns correctly:

<table>
  <thead>
    <tr>
      <th>Name</th>
      <th>ID</th>
      <th>Parameters</th>
    </tr>
  </thead>
  <tbody>
    <!-- Iterate over your actual myArray, each "item" is an object in the array -->
    <tr ng-repeat="item in $ctrl.myArray track by item.id">
      <td>{{item.name}}</td>
      <td>{{item.id}}</td>
      <td>
        <!-- Loop through the parameters array for each item -->
        <span ng-repeat="param in item.parameters track by $index">
          {{param}}
          <!-- Add a comma separator between parameters (except the last one) -->
          <span ng-if="!$last">, </span>
        </span>
      </td>
    </tr>
  </tbody>
</table>

Key Improvements

  • Proper Data Access: Instead of using $index to reach into the array, we directly use the item variable from the ng-repeat to access item.name, item.id, and item.parameters—this is cleaner and matches your data structure.
  • Iterate Over Parameters: The inner ng-repeat loops through each parameter in the item.parameters array, so every value gets displayed.
  • Cleaner Track By: Using track by item.id (since id is unique) is better practice than track by $index—it helps Angular render rows more efficiently when the array changes.

This should make your third column display all the parameters for each row as expected!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 12:19:40