简体   繁体   English

如何在另一个查询循环中执行查询循环

[英]How to do execute a query loop inside of another query loop

so my question is, how i can achieve this: I have an array of dates and an array of locations, i want to iterate the array of dates, and for each date, execute some query's, them iterate the whole array of locations doing an query for each item and them return an JSON response with the data.所以我的问题是,我怎么能做到这一点:我有一个日期数组和一个位置数组,我想迭代日期数组,并且对于每个日期,执行一些查询,他们迭代整个位置数组做一个查询每个项目,它们返回一个 JSON 响应和数据。

PS I am using TypeOrm and i am also novice PS我正在使用TypeOrm,我也是新手

If you've got two arrays, and you want to loop one inside of the other, then... just do that.如果您有两个 arrays,并且您想将一个循环到另一个内部,那么……就这样做。

 var locations = ['Paris','St Louis','Moscow']; var dates = ['wednesday', 'thursday', 'friday']; async function run(locations, dates) { let results = []; for (let location of locations) { for (let date of dates) { console.log(`${location} - ${date}`); const newResults = await query(location, date); results = results.concat(newResults); } } return results; } run(locations, dates);

edited to include async query example编辑以包含异步查询示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM