【发布时间】:2020-09-29 03:09:32
【问题描述】:
试图让数据显示在我的表格中。我认为我没有正确地进行数据绑定。
其中一个接口返回一个不同接口的数组,如下所示:
import { ExceptionDetailLine } from './exception-detail-line-interface';
export interface ExceptionReportData {
exceptionReportTitle: string,
exceptionReportLines: Array<ExceptionDetailLine>
}
ExceptionDetailLine接口:
export interface ExceptionDetailLine {
itemId: string,
altItemId: string,
genName: string,
stationName: string,
hospitalCode: string,
facility: string,
reason: string
}
如何让exceptionReportLines 显示在表格中?
这是我没有运气的尝试:
<p-table class="table table-striped"
[columns]="cols"
[value]="sessionReportData"
[paginator]="true"
sortMode="multiple"
sortField="station"
[rows]="10"
[totalRecords]="totalCases"
[rowsPerPageOptions]="[10, 25, 50]"
[showCurrentPageReport]="true"
[responsive]="true"
[resizableColumns]="true">
<ng-template pTemplate="header" let-columns>
<ng-template pTemplate="colgroup" let-columns>
<colgroup>
<col *ngFor="let col of columns">
</colgroup>
</ng-template>
<tr>
<th *ngFor="let col of columns" pResizableColumn [pSortableColumn]="col.field">
{{ col.header }}
<p-sortIcon [field]="col.header"></p-sortIcon>
</th>
</tr>
</ng-template>
<ng-template pTemplate="body">
<tr *ngFor="let s of sessionReportData.exceptionReportLines">
<td>{{ s.itemId }}</td>
<td>{{ s.altItemId }}</td>
<td>{{ s.genName }}</td>
<td>{{ s.stationName }}</td>
<td>{{ s.hospitalCode }}</td>
<td>{{ s.facility }}</td>
<td>{{ s.reason }}</td>
</tr>
</ng-template>
这是在我的 component.ts 中检索数据的方式:
public async orderExceptionReportData(): Promise<void> {
return this.orderExceptionReportService.OrderExceptionReport(this.sessionReportFilter)
.then(
data => {
this.sessionReportData = data;
console.log(this.sessionReportData)
});
}
【问题讨论】:
-
您使用 Promise 而不是 observables 有什么特别的原因吗?因为我认为当组件模板被渲染时你的承诺还没有解决。
标签: html angular typescript data-binding