有必要根据此条件c.date <= this.selectedReport.report_date
找到最合适的日期(显示一个值)。但是条件if (Math.max(...this.costs.map(c => c.date))){}
的这一部分不起作用,因此完全不显示数据。我怎样才能解决这个问题?没有任何错误。
reports: Reports[]
income: Income[]
costs: Costs[]
selectedReport = null
filteredIncome = []
filteredСosts = []
onSelectedReport(reportId) {
this.selectedReport = this.reports.find(
el => {
return el.report_id === reportId
}
)
if (this.incomeService) {
this.incomeService.fetchAll().subscribe(
income => {
this.income = income
this.filteredIncome = this.income.filter(
(income) => income.income_id == this.selectedReport.r_income_id
)
if (this.costsService) {
this.costsService.fetch().subscribe(
costs => {
this.costs = costs
for(let i of this.filteredIncome){
for(let c of costs){
if(Math.max(...this.costs.map(c => c.date))) {
if(c.costs_id==i.i_costs_id){
if (c.date <= this.selectedReport.report_date) {
this.filteredСosts.push(c)
}
}
}
}
}
}
)
}
}
)
}
}
试图使用库ngx-pipes。并从循环if (Math.max(...this.costs.map(c => c.date))){}
中删除此行,并将其替换为:
<div *ngFor="let report of reports" class="center " (click)="onSelectedReport(report.report_id)">
<a>{{report.report_date | date: 'dd.MM.yyyy'}}</a>
</div>
<div *ngIf="selectedReport">
<div *ngFor="let i of filteredIncome">
<div *ngFor="let c of filteredСosts | max: 'date'">
{{c.name}}
</div>
</div>
</div>
我收到此错误:
错误错误:找不到其他支持对象“ -Infinity” 输入“数字”。 NgFor仅支持绑定到Iterables,例如 数组。
atNgForOf.push ../ node_modules/@angular/common/fesm5/common.js.NgForOf.ngDoCheck (common.js:3152)
在checkAndUpdateDirectiveInline(core.js:9246)
在checkAndUpdateNodeInline(core.js:10507)
在checkAndUpdateNode(core.js:10469)
在debugCheckAndUpdateNode(core.js:11102)
在debugCheckDirectivesFn(core.js:11062)
at Object.eval [作为updateDirectives](RepHoursComponent.html:48)
在Object.debugUpdateDirectives [作为updateDirectives](core.js:11054)
在checkAndUpdateView(core.js:10451)
在callViewAction(core.js:10692)
答案 0 :(得分:0)
如果c.date
是Date JavaScript对象,请尝试使用此c.date.getTime()
答案 1 :(得分:0)
删除math.max检查并应用以下内容。
(... this.costs.map(c => c.date)){if(Math.max(c => c.date)){}}