我正在尝试使用primeng创建树表html文件。Html 文件应该能够呈现在 JSON 文件之下。
以下是 Json响应。
{
"data": [
{
"data": {
"Briname": "Aamir",
"aantalPersonen": "122"
},
"children": [
{
"data": {
"Vestiging": "Ranchi",
"aantalPersonen": "102"
},
"children": [
{
"data": {
"Singalcode": "4",
"aantalPersonen": "15"
}
},
{
"data": {
"Singalcode": "5",
"aantalPersonen": "10"
}
}
]
},
{
"data": {
"Vestiging": "Bangalore",
"aantalPersonen": "82"
},
"children": [
{
"data": {
"Singalcode": "6",
"aantalPersonen": "15"
}
}
]
}
]
},
{
"data": {
"Briname": "Abhinav",
"aantalPersonen": "122"
},
"children": [
{
"data": {
"Vestiging": "Bangalore",
"aantalPersonen": "102"
},
"children": [
{
"data": {
"Singalcode": "4",
"aantalPersonen": "15"
}
}
]
}
]
}
]
}
这里,父节点以“Brinname”作为关键数据元素名称,子节点以“vestging”和“Singalcode”作为数据元素。
我们如何使用树表来实现这一点?
HTML:
<p-treeTable [value]="files2" [columns]="cols" selectionMode="single" [(selection)]="selectedNode1" (onNodeSelect)="nodeSelect($event)">
<ng-template pTemplate="body" let-rowNode let-rowData="rowData" let-columns="columns" >
<tr [ttSelectableRow]="rowNode">
<td *ngFor="let col of columns; let i = index">
<p-treeTableToggler [rowNode]="rowNode" *ngIf="i == 0"></p-treeTableToggler>
{{rowData[col.field]}}
</td>
</tr>
</ng-template>
</p-treeTable>