【发布时间】:2020-12-17 02:26:21
【问题描述】:
想知道是否可以从 JSON 数据创建动态材料表。列和标题的数量应根据 JSON 中的键而变化。例如这个 JSON 应该创建这个表:
{
color: "green", code: "#JSH810"
}
,
{
color: "red", code: "#HF59LD"
}
Color Code
green #JSH810
red #HF59LD
这个 JSON 应该创建这个表:
{
id: "1", type: "bus", make: "VW", color: "white"
}
,
{
id: "2", type: "taxi", make: "BMW", color: "blue"
}
id type make color
1 bus VM white
2 taxi BMW blue
它应该是一个材料表,我知道如何在 HTML 表中使用 ngFor 实现这一点
<table>
<thead>
<tr>
<th *ngFor="let head of items[0] | keys">{{head}}</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let item of items">
<td *ngFor="let list of item | keys">{{item[list]}}</td>
</tr>
</tbody>
</table>
谁能帮我把它转换成材料表?
【问题讨论】:
-
工作示例:therichpost.com/…
-
对不起,该示例不是动态列示例。
标签: angular