【发布时间】:2021-02-22 01:24:09
【问题描述】:
我正在尝试将一些 JSON 数据映射到 Angular 组件。这是我尝试使用的数据:
[
{
"P1": [
{
"pc1": "XYZ",
"pn1": "Testp",
"pv1": 123,
"m1": [
{
"mn1": "XYZ",
"ma1": 12,
"mv1": 123456
},
{
"mn1": "Testm",
"ma1": 23,
"mv1": 22565
},
{
"mn1": "Testmn",
"ma1": 34,
"mv1": 234567
}
]
}
]
}
]
这是我要渲染的 HTML 表格:
<table class='table table-striped' aria-labelledby="tableLabel" *ngIf="apiValues">
<thead>
<tr>
<th>PC1</th>
<th>PN1</th>
<th>PV1</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let apiValue of apiValues">
<td> {{ apiValue.pc1 }} </td>
<td> {{ apiValue.pn1 }} </td>
<td> {{ apiValue.pv1 }} </td>
</tr>
</tbody>
</table>
我正在尝试将一些 JSON 数据映射到 Angular 组件。这是我正在尝试使用的数据。
【问题讨论】:
-
你能再解释一下你的问题吗?
-
也许你只需要使用 JSON.parse(myJsonData); 将 json 转换为 js 对象即可。 ?
标签: html json angular typescript