【问题标题】:Bind the table body with n number of columns in Angular 8在Angular 8中将表体与n列绑定
【发布时间】:2023-03-21 05:12:02
【问题描述】:

我正在从 API 获取列名未知的数据。我能够绑定表头但无法绑定 tbody 行的列.. 例如,数据将是这样的。

  [{name: "jean", surname: "kruger"}, {name: "bobby", surname: "marais"}];
OR
  [{name: "jean", email: "a@a.com"}, {name: "bobby", email: "b@b.com"}]; // anything

<table>
   <thead>
      <tr><th *ngFor="let col of headers">{{col}}></th></tr>
   </thead>
   <tbody>
      <tr *ngFor="let obj of data">
         <td *ngFor="let col of headers"> {{obj[col]}} </td> // Its not working
                               OR
          <td *ngFor="let col of headers"> {{obj.col}} </td> // Its not working, will be column sequence mapping issue
      </tr>
   </tbody>
</table>

**如何解决这个问题? 谢谢.. **

【问题讨论】:

    标签: angular


    【解决方案1】:

    请检查我创建的以下代码示例。我想,我在那里解决了你的问题。

    https://stackblitz.com/edit/angular-ivy-dbx49v

    【讨论】:

      猜你喜欢
      • 2020-05-30
      • 1970-01-01
      • 1970-01-01
      • 2020-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-06
      相关资源
      最近更新 更多