【发布时间】:2020-08-31 20:27:24
【问题描述】:
我有一个带有嵌套数组的对象数组,如下所示。如何使用 ngFor 在表中打印嵌套数组值。 数组如下所示:
我正在使用表格来打印这些值,以便将表格导出到 Excel 工作表。
表格如下:
<table class="table table-bordered">
<thead class="thead-dark">
<tr>
<th>Hours</th>
<th>Dates</th>
<th>Project Codes</th>
</tr>
</thead>
<tbody class="tbody" *ngFor="let value of array; let i = index">
<tr *ngFor="let item of array[i].item; let dateValue of array[i].datesArray; let h of array[i].hours">
<td>{{h}}</td>
<td>{{dateValue}}</td>
<td>{{value.projectCodeInput}}</td>
</tr>
</tbody>
</table>
我在 ngFor 的单个标签上使用多个数组,如下所示: {*ngFor="let item of array[i].item; let dateValue of array[i].datesArray; let h of array[i].hours"} 我知道这是错误的方式,但不知何故,两个地方的输出中都会打印小时数,覆盖第二列中的 dateValue。
有没有办法在同一元素(TABLE)中打印小时、dateValue 数组中的值?
【问题讨论】: