我正在使用MongoDB集合来填充Ag Grid,现在我想获取列列表。我能够加载数据,并希望将列名称用于项目的将来。 Ag Grid确实具有getAllGridColumns()的内置选项。但是我想从后端获得它。我的代码是:
setMasterData (state, payload) {
if (!payload) {
state.tableData.rows = [];
} else {
// First column holds the buttons to delete the row item
let cols = [{
field: '',
headerName: 'Actions',
width: 200,
colId: 'params',
cellRendererFramework: 'gridEditButtons'
}];
cols = cols.concat(Object.keys(payload[0]).map(x => {
return {
field: x,
headerName: x.replace(/([A-Z])/g, ' $1').replace(/^./, function (txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); })
};
}));
state.tableData.cols = cols;
state.tableData.rows = payload;
}
},
如何检查数组tableDala.cols中的列名?