【发布时间】:2020-02-18 11:54:29
【问题描述】:
我正在尝试制作一个显示两个时间段销售额的比较报告,在这种情况下,我选择了 10 月 1 日至 31 日和 11 月 1 日至 30 日。我从同一个 Json 文件加载数据,但作为两个单独的查询,第一个使用 10 月期间,第二个使用 11 月期间。
这是我目前拥有的代码:
// October 1-31
<div class="col-6" *ngFor="let periods of reportData">
<div *ngFor="let reportVal of periods.groupedTransactions">
<div class="row" *ngIf="reportData.length > 0">
<div class="col-12">
<h6>Customer: {{reportVal.name}}</h6>
</div>
<div class="col">
<h6>Total Sales: {{reportVal.totalSales | number}}</h6>
</div>
</div>
</div>
</div>
// November 1-30
<div class="col-6" *ngFor="let comPeriods of comReportData">
<div *ngFor="let reportVal of comPeriods.groupedTransactions">
<div class="row" *ngIf="comReportData.length > 0">
<div class="col-12">
<h6>Customer: {{reportVal.name}}</h6>
</div>
<div class="col">
<h6>Total Sales: {{reportVal.totalSales | number}}</h6>
</div>
</div>
</div>
</div>
结果如下:
如果该客户没有销售,有没有办法添加一个函数,该函数将在 11 月添加一个空行?我想让所有客户垂直对齐。
因为 for 循环的周期是基于选定的日期,所以将列放在同一个循环中只会获取一个日期的数据。
如果有人可以帮助我或告诉我在哪里可以解决这个问题,我们将不胜感激!
【问题讨论】:
标签: javascript html angular loops for-loop