mysqlデータベースを2回クエリしていますが、2回目、それぞれの結果に対して複数回クエリを実行しようとしていますが、NodeJSは毎回結果を待っているforeachループの中でpromise-mysqlクエリを実行しています
admin.get('/', function (req, res) {
mysqlQ("SELECT I.ID as ID, C.ID AS CID, I.PD AS PostDate, C.Name AS CatName, U.UserName AS UserName, I.Title AS Title, I.Post AS PostData FROM categories AS C JOIN INAT AS I ON C.ID = I.Category JOIN Users AS U on U.ID = I.User").then(function (INAT) {
INAT.forEach(function (team) {
team.time = moment(team.PostDate).format("DD-MM-YYYY HH:mm:ss");
team.TS = moment(team.time, "DD-MM-YYYY HH:mm:ss").fromNow();
mysqlQ("SELECT I.ID AS InatID, J.Name AS JobTitle, C.Name AS Category FROM `Jobs` AS J JOIN Jobs2INAT AS J2I ON J.ID = J2I.JobsID JOIN INAT AS I ON I.ID = J2I.INATID JOIN categories AS C on C.ID = J.Categories WHERE I.ID = " + team.ID).then(function (jobs) {
team.jobs = jobs;
});
});
var context = {
INAT: INAT
};
var homeTemplate = pug.compileFile(__dirname + '/templates/home.pug');
var html = homeTemplate(context);
res.send(html);
});
})
可能な複製を終了することを忘れないでください非同期呼び出しからの応答?](http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) - このコードはNodeJSであり、AJAXではありません同じ原則が適用されます –