所以基本上我在 start 函数中推送一个名为 TripsData 的 ArrayList 中的值,但是一旦我退出函数,它就会变空,所以我不能进一步超出。旅行只是一个数组[1,2,3,4]
代码如下...
const TripsData = []; // I need to push data in this array
await trips.forEach((trip) => {
async function start() {
const url = await TripMedia.findOne({ // i get my url here
where: { tripID: trip },
})
.then((result3) => {
const url = result3.mediaURL;
return url;
})
.catch((error) => {
console.log(error);
});
const subject = await TripDetails.findOne({ // i get my subject here
where: { tripID: trip },
})
.then((result3) => {
const subject = result3.subject;
return subject;
})
.catch((error) => {
console.log(error);
});
TripsData.push({
tripId: trip,
mediaURL: url,
subject: subject,
}); // The value is getting pushed here
}
start();
});
console.log(TripsData) // If i try to get data here its not present
Reply.push({
"locationId":location,
"locationName": dict[location],
"trips": TripsData
}) // so the value of tripsData is like [] only ... how to get data
价值观即将到来
TripsData.push({
tripId: trip,
mediaURL: url,
subject: subject,
});
但是 forEach 之外的值会变空吗?问题是为什么会这样以及如何解决
提前感谢您的上帝级帮助
