我正在使用c3.js来显示一个图表,该图表的各个部分随位置而异。在单击零件时,我从中获取位置并过滤我的主数据。然后,我需要在下面显示一个表,其中显示了过滤记录。
我的代码部分如下:
resultData;
filteredData;
constructor(private appService: AppService) { }
ngOnInit(){
this.apiService.getData('/reportees').subscribe((res)=>{
this.resultData=JSON.parse(res._body);
let value=JSON.parse(JSON.stringify(this.resultData));
this.chart = c3.generate({
data: {
onclick:function(d,element){
this.filteredData=value.filter((record)=>record.location==d.id);
console.log(this.filteredData);
}
[当我执行onclick时,我可以看到filteredData记录在浏览器控制台上。但是在表中,我看不到行被填充。已知的是filterData在页面加载时未定义,因为未填充哪些行。在这种情况下,请在区域点击时动态显示表格中的记录。
[尝试显示在表中时,您可能要检查是否使用了异步管道或安全的导航操作符。
例如
{{filteredData?.something}}
或
{{filteredData.something | async}}