Max*_* R. 6 angular-pipe angular ngx-charts
我正在使用带有ngx-charts数据数组的过滤器管道.数据按2个日期过滤:fromDate和toDate.当使用使数组变小的日期进行过滤时,管道工作正常,但是当我首先使用较小的日期范围过滤然后再次使范围变大时,管道不能与原始数组一起使用,而是使用已经过滤的数组.
我已经做了其他的点子,从来没有遇到过这个问题,我不确定这里出了什么问题.也许有人可以帮助我.
管:
export class DateInRangePipe implements PipeTransform {
transform(obj: any[], from: Date, to: Date): any[] {
if (obj && from && to) {
obj.forEach(data => {
data.series = data.series.filter((item: any) => {
return this.inRange(item.name, from, to);
});
});
}
return [...obj];
}
inRange(date: Date, from: Date, to: Date): boolean {
return date.getTime() >= from.getTime() &&
date.getTime() <= to.getTime() ? true : false;
}
}
Run Code Online (Sandbox Code Playgroud)
Chart.component.html部分
<ngx-charts-line-chart
[view]="view"
[scheme]="colorScheme"
[results]="multi | dateinrangePipe: from: to"
[gradient]="gradient"
[xAxis]="showXAxis"
[yAxis]="showYAxis"
[legend]="showLegend"
[showXAxisLabel]="showXAxisLabel"
[showYAxisLabel]="showYAxisLabel"
[xAxisLabel]="xAxisLabel"
[yAxisLabel]="yAxisLabel"
[autoScale]="autoScale"
(select)="onSelect($event)">
</ngx-charts-line-chart>
Run Code Online (Sandbox Code Playgroud)
`data.series = data.series.filter...`
Run Code Online (Sandbox Code Playgroud)
是对原始对象的引用。要中断引用,必须在开始时创建 obj 数组的克隆。
归档时间: |
|
查看次数: |
823 次 |
最近记录: |