Передаю со стороны сервера массив состоящий из двух объектов. Как правильно его разбить на два отдельных на стороне веба?
принимаю на стороне веба:
fetch('/relocate',{
method: 'POST',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify(currentElem)
})
.then(response => response.json())
.then(json => console.log("json", json))
// .then(json => console.log("firstWindow",json[0].table))
// .then(json => console.log("secondWindow",json[1].table))
.then(json =>this.$emit("newvalueforbothwindows", json))
},
серверная часть
router.post('/relocate', (req, res) =>{
console.log("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS");
const fs = require("fs-extra");
let body = "";
req.on("data", function (data) {
body += data;
});
req.on("end", function(currentData) {
currentData = JSON.parse(body);
console.log('дата',currentData);
let from = currentData.dir + "\\" +currentData.fileName;
console.log("откуда", currentData.dir);
let where = currentData.where + "\\" +currentData.fileName;
console.log("куда", where);
console.log("что", from);
fs.copySync(from, where);
if(currentData.sizeOrType === "<папка>"){
deleteFolderRecursive(currentData.dir + "\\" + currentData.fileName);
}else{
fs.unlinkSync(currentData.dir + "\\" + currentData.fileName);
}
foo(currentData.dir, pathToFile1);
foo(currentData.where, pathToFile2);
let objForRedrowBothWindows = [];
objForRedrowBothWindows.push(fs.readFileSync(pathToFile1, 'utf8'));
objForRedrowBothWindows.push(fs.readFileSync(pathToFile2, 'utf8'));
console.log(objForRedrowBothWindows);
res.json(objForRedrowBothWindows);
// res.sendFile(path.resolve(pathToFile1));
// res.sendFile(path.resolve(pathToFile2));
});
});
на сервере данные выглядят так:
'{"table":[{"icon":0,"fileName":"11111","sizeOrType":"<папка>","dateOfChange":"2020-10-04T19:38:09.517Z","dir":"C:\\\\\\\\test"},{"icon":1,"fileName":"2222","sizeOrType":"<папка>","dateOfChange":"2020-10-04T19:13:32.976Z","dir":"C:\\\\\\\\test"},{"icon":2,"fileName":"444444","sizeOrType":"<папка>","dateOfChange":"2020-10-04T19:38:11.001Z","dir":"C:\\\\\\\\test"},{"icon":3,"fileName":"Новая папка","sizeOrType":"<папка>","dateOfChange":"2020-10-04T13:05:08.541Z","dir":"C:\\\\\\\\test"},{"icon":4,"fileName":"Новый текстовый документ.txt","sizeOrType":"0 байт","dateOfChange":"2020-10-04T12:52:54.356Z","dir":"C:\\\\\\\\test"}]}',
'{"table":[{"icon":0,"fileName":"33333","sizeOrType":"<папка>","dateOfChange":"2020-10-04T19:38:17.428Z","dir":"C:\\\\\\\\test2"},{"icon":1,"fileName":"Новый текстовый документ — копия (2).txt","sizeOrType":"0 байт","dateOfChange":"2020-10-04T18:06:55.457Z","dir":"C:\\\\\\\\test2"},{"icon":2,"fileName":"Новый текстовый документ — копия (3).txt","sizeOrType":"0 байт","dateOfChange":"2020-10-04T18:06:55.457Z","dir":"C:\\\\\\\\test2"},{"icon":3,"fileName":"Новый текстовый документ — копия.txt","sizeOrType":"0 байт","dateOfChange":"2020-10-04T18:06:55.457Z","dir":"C:\\\\\\\\test2"}]}'