【发布时间】:2018-10-23 07:29:33
【问题描述】:
我正在将大量的 Excel 电子表格翻译成 json,然后构建一个工具来格式化数据并将其用于分析。
在上传过程中,我向用户展示了他们所有数据的视图。我在格式化表格时遇到了一些麻烦,我希望这里有人可以帮助解释这个问题:
在 html 中使用标准数据表时,我可以在硬编码时轻松获得我想要的结果:
<div style="margin-bottom: 10px">
<table class="table table-responsive table-condensed">
<tr>
<th style="color: black" *ngFor="let label of lineChartLabels">{{label}}</th>
</tr>
<tr *ngFor="let d of XLSData">
<td>This is in Column 1</td>
<td>And this is in Column 2</td>
</tr>
</table>
</div>
我明白了: 但是当用 NgFor 填充行时,我会得到每列重复的数据:
<div style="margin-bottom: 10px">
<table class="table table-responsive table-condensed">
<tr>
<th style="color: black" *ngFor="let label of lineChartLabels">{{label}}</th>
</tr>
<tr *ngFor="let d of XLSData">
<td style="color: black" *ngFor="let label of lineChartLabels">Time: {{d.Time | json}}</td>
<td style="color: black" *ngFor="let label of lineChartLabels">Empty: {{d.__EMPTY | json}}</td>
</tr>
</table>
</div>
我不明白为什么循环会用相同的数据填充每一列可用的数据,因为数据不会在 JSON 数组中重复。
【问题讨论】:
标签: angular typescript html-table