将对象类型转换为数组并进行key的转换

 

 

   getChartData() {
      const { schoolId } = this.chartParams
      this.getEquCountAndType({ schoolId }).then(res => {
        console.log(res)        // {"DV86-LA":7,"55X":1,"DV75-LA":1}
        this.chartData = Object.entries(res).map(([name, value]) => ({
          name,
          value,
        }))
        console.log(this.chartData)       // [{name: "DV86-LA"value: 7}, {name: "DV75-LA"value: 1}, {name: "DV75-LA"value: 1}]
      })
    },
posted @ 2020-04-24 10:53  花囍  阅读(661)  评论(0编辑  收藏  举报