【发布时间】:2018-01-16 05:14:35
【问题描述】:
我想在我的async forEach 循环之后运行代码。
myPosts.forEach(function(post) {
getPostAuthor(post.authorID, function(postAuthor) {
post.author = postAuthor;
}
});
res.render('index', {
posts: myPosts
});
res.end();
在上面的代码中,首先 res.render 运行,然后 forEach 填充 post.author
【问题讨论】:
-
forEach 不是异步的。 getPostAuthor 是。
-
不,但我敢打赌
getPostAuthor()是。 -
我的意思是 forEach 中的函数
-
堆栈溢出时这里有数百个重复项。
标签: async javascript node.js asynchronous callback