我阅读了json2csv文档并将其应用到我的程序中
const {parse} = require('json2csv')
header = [customerNo,Name,BranchCode,representive,overall]
list = [{cNo:1,name:Jack,bCode:3,rps:Bill,overall},{cNo:2,name:Justin,bCode:2,rps:Wade,overall:180}]
const fields = header;
const opts = { fields };
try {
var csv = parse(list,opts);
csv=csv.replace(/,/g,";")
console.log(csv);
} catch (err) {
console.log(err)
}结果= customerNo;Name;BranchCode;representive;overall
我的数据不在标题下。为什么我会有这样的问题。我做错了什么吗?
发布于 2020-07-03 02:09:51
由于所需的列名与属性键不同,因此需要将它们定义为自定义的:
const fields = [{
label: 'customerNo',
value: 'cNo'
}, {
label: 'Name',
value: 'name'
}, {
label: 'BranchCode',
value: 'bCode'
}, {
label: 'representive',
value: 'rps'
}, {
label: 'overall',
value: 'overall'
}
];docs -> https://github.com/zemirco/json2csv#example-3中也对此进行了说明
https://stackoverflow.com/questions/62699859
复制相似问题