module.exports= {
getHomePost:function(req,res) {
post_model.getHomePosts('1',function(err,rows) {
var locals={};
async.parallel([
function(callback) {
for(var i=0;i<rows.length-1;i++) {
async.series([
function(call){
post_model.getPostDetails(rows[i].Post_Date_Time_id,rows[i].Post_Personid_id,function(err,row) {
locals.rows[]=row;
call();
});
}
],function(err){
//console.log(locals.rows);
});
}
callback();
}
],function(err) {
console.log(locals.rows);
res.render('home',locals);
});
});
}
}
“我希望在从for循环获取输出后执行渲染。但我无法做到这一点..请帮忙。 在从循环中获取值之前,我的回调函数执行。但我想在从for循环“
获得输出后执行它答案 0 :(得分:0)
这可能会对你有帮助....
module.exports=
{
getHomePost:function(req,res)
{
post_model.getHomePosts('1',function(err,rows)
{
var locals={};
async.parallel([
function(callback)
{
var count = 0;
for(var i=0;i<rows.length-1;i++)
{
async.series([
function(call)
{
post_model.getPostDetails(rows[i].Post_Date_Time_id,rows[i].Post_Personid_id,function(err,row)
{
locals.rows[]=row;
call();
});
}],
function(err)
{
//console.log(locals.rows);
});
count++;
}
if(count == rows.length)
{
callback();
}
}],
function(err)
{
console.log(locals.rows);
res.render('home',locals);
});
});
}
}