Using node and express, I'm trying to process some information before the response renders the page, but I'm not having any luck doing so. Any suggestions?
app.get("/Category", function (request, response) {
if (request.query.Id) {
// get all the posts by categoryId
ForumPost.find({categoryId: request.query.Id}, function (err, posts) {
if (err) throw err;
var usernames = {};
for (i = 0; i < posts.length; i++) {
User.findById(posts[i].userId, function (err, user) {
if (err) throw err;
var username = user.username;
usernames[i] = username;
});
}
response.render("Category", {
message: posts,
userList: usernames
});
});
}
});
via JesseS102
No comments:
Post a Comment