如何在打字稿中创建函数

时间:2019-01-28 11:24:16

标签: javascript typescript

1。我的数据如下:

[{
    "BatchConfigName": "End1",

    "EndDateTime": "2019-01-06T11:10:00"
  },
  {
    "BatchConfigName": "End2 - Non-Gas",

    "EndDateTime": "2019-01-07T05:54:00"
  },
  {
    "BatchConfigName": "Secure",

    "EndDateTime": "2019-01-07T04:48:00"
  }
}
  1. 我想创建分配该数据的打字稿功能,例如

    var datawebsiteViewsChart = {
    labels: ['End1', 'End2 - Non-Gas', 'Secure'],
    series: [
        [11: 10, 05: 54, 04: 48]
    ]
    };
    

1 个答案:

答案 0 :(得分:0)


function map(data) {
    const labels = [];
    const series = [];

    for (itemKey of data) {
        labels.push(itemKey);
        series.push(data[itemKey]);
    }

    return {
        labels,
        series
    };
}