【问题标题】:Load data to a table onclick of an region in C3 JS [duplicate]将数据加载到 C3 JS 中某个区域的单击表中 [重复]
【发布时间】:2019-12-18 08:14:47
【问题描述】:

我正在使用 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);
            }

当我执行点击操作时,我可以看到过滤数据正在登录浏览器控制台。但在表中,我没有看到填充的行。众所周知,由于没有填充哪些行,所以在页面加载时未定义过滤数据。在这种情况下,请帮助在点击区域时动态显示表格中的记录。

【问题讨论】:

    标签: javascript angular c3.js


    【解决方案1】:

    在尝试将其显示在表格中时,您可能需要检查是否使用了异步管道或安全导航运算符。

    例如,

    {{filteredData?.something}} 或

    {{filteredData.something | async}}

    【讨论】:

    • 不是这样,resultData 是订阅时出现的,它在加载时发生。稍后,仅在 onclick 触发器上获取并过滤 resultData 的克隆并将其传递给过滤数据。由于html被加载一次,我认为视图不会改变。
    • 你能创建一个相同的堆栈闪电战吗?
    猜你喜欢
    • 2015-09-10
    • 2016-06-08
    • 2015-08-08
    • 2015-10-01
    • 1970-01-01
    • 2018-03-02
    • 1970-01-01
    • 2011-01-13
    • 1970-01-01
    相关资源
    最近更新 更多