【发布时间】:2021-03-10 20:36:15
【问题描述】:
我有一个这样的数组
tdata = {
jam: [1, 2, 4, 5],
ram: [11, 12, 34, 14],
sam: [21, 22, 23, 24],
jug: ["a", "b", "c", "d"],
tam: [31, 32, 33, 34]
};
` 我想打印/显示对象键,如 jam、ram、sam 作为表头及其在相应表中的值与 Pprimeng 表的角度。我尝试了各种方法,但无法正确显示。 动态值的primeng表
<p-table [columns]="cols" [value]="products">
<ng-template pTemplate="header" let-columns>
<tr>
<th *ngFor="let col of columns">
{{col.header}}
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-rowData let-columns="columns">
<tr>
<td *ngFor="let col of columns">
{{rowData[col.field]}}
</td>
</tr>
</ng-template>
</p-table>
如果我想显示我需要数组自动在表单中
tdata = [
{jam:1,ram:11,sam:21,jug:"a",tam:31},
{jam:2,ram:12,sam:22,jug:"b",tam:32},
{jam:3,ram:34,sam:23,jug:"c",tam:33},
{jam:5,ram:14,sam:24,jug:"d",tam:34 }
]
tdata 中的值可能会动态变化,它们来自后端和键
【问题讨论】: