我将从后端获取一个JSON对象,它看起来像:
export class Testobject {
name: string;
organization: string;
mrn: string;
checkresults: CheckResult[];
}
export class CheckResult {
message: string;
errortyp: string;
name: string;
timestamp: string;
}
每个测试对象都有一个包含不同长度不同CheckResults的数组。 我想在表格中显示数据。表格的标题是固定的。 我不知道如何将数组的元素分配到正确的列中。
我的问题是checkresult数组可能只包含2/3或1/3 checkresults。 例如,如果只有一个可用于第三列,那么我该如何放置它?
这是我目前的方法:
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Organization</th>
<th>Result</th>
<th>Date / Time</th>
<th>CheckResult name 1</th>
<th>CheckResult name 2</th>
<th>CheckResult name 3</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let testobject of testobjects">
<td>{{testobject.mrn}}</td>
<td>{{testobject.name}}</td>
<td>{{testobject.organization}}</td>
<td *ngFor="let checkresult of testobjects.checkresults">
<div *ngIf="checkresult.errortyp == 'Error'" class="ccrdot red"></div>
<div *ngIf="checkresult.errortyp == 'Warning'" class="ccrdot yellow"></div>
<div *ngIf="checkresult.errortyp == 'successful'" class="ccrdot green"></div>
<div *ngIf="checkresult.errortyp == null" class="ccrdot"></div>
</td>
<td>{{checkresult.timestamp}}</td>
</tr>
</tbody>
期望结果:
每个CheckResult都有一个名称,显示它属于哪一列。
Id Organization mrn check name 1 check name 2 check name 3
----------------------------------------------------
to1 | org1 | 1 | error | | error <- 2 element in Array
to2 | org2 | 2 | | | error <- 1 elements in Array
to3 | org3 | 1 | | error | <-1 element in Array