我有嵌套对象,我想传递给 PrimeNG 动态表,但它看起来没有发生。无论我在哪里嵌套对象,我都会像往常一样传递它,但不会发生。
PrimeNG 是否需要遵循任何特定规则
.html
<p-table [columns]="cols" [value]="MyData">
<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>
.ts
this.cols = [
{ field: 'NAME', header: 'Name' },
{field: 'AGE', header: 'Age' },
{field: 'ADDRESS.POSTCODE', header: 'Post Code' }
{field: 'ADDRESS.ZIPCODE', header: 'Zip' }
];
.JSON
[
{
"NAME": "ABC",
"AGE": "000",
"ADDRESS": {
"POSTCODE": "00",
"ZIPCODE": "1212"
}
},
{
"NAME": "XYZ",
"AGE": "000",
"ADDRESS": {
"POSTCODE": "00",
"ZIPCODE": "1212"
}
}
]