VsCode执行JavaScript|js保存文件到记事本

const fixedData = [{ "organizationId": 93, "quantity": 1200, "comments": "", "lotsNum": "109766H2206130GA", "transDate": 1656691607000, "lineId": 3560117, "materialCode": "1309020023", "lableCode": "L1309020023#22103638109766H2206130GA", "ckNumber": "CKA02202207022235656", "headerId": 1670183, "operator": "053643" },
{ "organizationId": 93, "quantity": 1200, "comments": "", "lotsNum": "109766H2206130GA", "transDate": 1656691607000, "lineId": 3560038, "materialCode": "1309020023", "lableCode": "L1309020023#22103638109766H2206130GA", "ckNumber": "CKA02202207022235657", "headerId": 1670183, "operator": "053643" },
{ "organizationId": 93, "quantity": 700, "comments": "", "lotsNum": "106450QYSF20220530-1", "transDate": 1656708679000, "lineId": 3560197, "materialCode": "1323020057", "lableCode": "L1323020057#22104280106450QYSF20220530-1", "ckNumber": "CKA02202207022235707", "headerId": 1670259, "operator": "053643" },
{ "organizationId": 93, "quantity": 894.1, "comments": "", "lotsNum": "115773PH20220627", "transDate": 1656708679000, "lineId": 3560260, "materialCode": "1323020057", "lableCode": "L1323020057#22106566115773PH20220627", "ckNumber": "CKA02202207022235708", "headerId": 1670259, "operator": "053643" },
{ "organizationId": 92, "quantity": 1250, "comments": "", "lotsNum": "101577G2206300NI", "transDate": 1656701974000, "lineId": 3560173, "materialCode": "1309010001", "lableCode": "L1309010001#22105838101577G2206300NI", "ckNumber": "CKA01202207022235697", "headerId": 1670255, "operator": "050665" },
{ "organizationId": 92, "quantity": 1250, "comments": "", "lotsNum": "101577G2206300NI", "transDate": 1656701974000, "lineId": 3560180, "materialCode": "1309010001", "lableCode": "L1309010001#22105838101577G2206300NI", "ckNumber": "CKA01202207022235698", "headerId": 1670241, "operator": "050665" }];

// import fs module in which writeFile function is defined. 
const fsLibrary = require('fs')
// Data which will need to add in a file. 
let sqltxt = '';
//处理数据
fixedData.some(item => {
    sqltxt += 'select ' + item.organizationId + ' organizationId, ' + item.quantity + ' quantity, ' + "'" + item.lotsNum + "'" + ' lotsNum, ' + item.transDate + ' transDate, ' + item.lineId + ' lineId, ' + "'" + item.materialCode + "'" + ' materialCode, ' + "'" + item.lableCode + "'" + ' lableCode, ' + "'" + item.ckNumber + "'" + ' ckNumber, ' + item.headerId + ' headerId, ' + "'" + item.operator + "'" + ' operator from dual union all\r\n';
});
// Write data in 'fixedData.txt' . 
fsLibrary.writeFile('fixedData.txt', sqltxt, (error) => {
    // In case of a error throw err exception. 
    if (error) throw err;
});

1、编写

2、运行

3、结果

posted @ 2022-07-21 20:07  Journey&Flower  阅读(251)  评论(0编辑  收藏  举报