AG-Grid 使用字段名替换创建行数据数组

AG-Grid create row data array using field name subsititutions

使用 AG Grid,我们使用后端返回的列名称填充列 defs 数组

考虑下面的数组,填充了后端返回的数据:

columnDefs: [
    { headerName: 'column_1', field: 'column_value_1' },
    { headerName: 'column_2', field: 'column_value_2' },
    { headerName: 'column_3', field: 'column_value_3' }
]

可以使用什么 TypeScript 语法来实现下面的伪代码段? :

given rowData = []
given rowOfValues = [ row_value_1 , row_value_2 , row_value_3 ] // From Back End
given rowOfColumnNames= [ column_value_1 , column_value_2 , column_value_3 ] // From Back End

for index = 0 ; while index < rowOfValues.size ; index++

 add to rowData  ( rowOfColumnNames[index] : rowOfValues[index] )

return rowData

根据 AG_Grid 规范,生成的 rowData 数组将如下所示:

rowData = [ { 
column_value_1: 'row_value_1', column_value_2 'row_value_2', column_value_3: row_value_3 } 
];
for ( let i = 0 ; i < rowOfValues ; i++ ) {

    object = {};

    object[rowOfColumnNames[i]] = rowOfValues[i];

    rowData.push(object);

}

return rowData;