简体   繁体   English

如何在打字稿中创建函数

[英]How to create a function in typescript

1.I have the data like below: 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. i want to create the typescript function that assign this data like我想创建分配此数据的打字稿函数,例如

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

    None没有任何


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

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

    return {
        labels,
        series
    };
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在TypeScript中使用返回类型创建函数? - How to create a function with return types in TypeScript? 如何创建使用 Typescript 传递函数的 React Context - How to create React Context that passes a function with Typescript 打字稿-创建一个回调函数 - typescript - create a callback function 如何在类中创建一个不会在TypeScript中使用原型函数的函数? - How to create a function in class that is not going to the prototyped function in TypeScript? 打字稿:如何为外部方法创建“ lambda函数调用”? - Typescript: How to create 'lambda function call' for external method? 如何为在打字稿中创建嵌套元素结构的函数创建接口? - How to create interface for a function which creates a nested element structure in typescript? 在 typescript 上创建具有泛型类型的 function - Create a function with generic type on typescript 如何在 TypeScript function 中创建一个空数组,并在每次调用 function 时向其中添加对象 - How to create an empty array within a TypeScript function, and add objects to it every time the function is called 创建对象/函数实例,将JavaScript转换为TypeScript - Create instance of object/function convert JavaScript to TypeScript 如何使用TypeScript创建AngularJs提供程序 - How to create a AngularJs provider with TypeScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM