使用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 }
];
答案 0 :(得分:0)
for ( let i = 0 ; i < rowOfValues ; i++ ) {
object = {};
object[rowOfColumnNames[i]] = rowOfValues[i];
rowData.push(object);
}
return rowData;