I got the following error: TypeError: undefined is not a function
callback(null, array_reply, threadResults);
this part seems bad but I don't know why.
I need your help. thanks
async.waterfall([
function (callback) {
Model.find()
.limit(10)
.sort({pushed_date: 'desc'})
.exec( function (err, results) {
if (err) {
log('Error: ' + err.message);
callback(err);
return;
}
var array_reply = new Array();
async.forEachSeries(results,
function (result, callback) {
var reply = result.replies[result.replies_count];
array_reply.push(reply);
},callback);
callback(null, array_reply);
});
},
function (array_reply, callback) {
Model.find()
.limit(10)
.sort( {replies_count: 'desc'} )
.exec( function (err, results) {
if (err) {
callback(err);
return;
}
callback(null, array_reply, results);
});
}
], function (err, array_reply, results) {
if (err) {
console.error("Error!");
return next(err);
}
res.render("aaa.hbs",{
models: results,
posts: array_reply
});
})
I changed my source like this.
async.waterfall([
function (callback) {
Model.find()
.limit(10)
.sort({pushed_date: 'desc'})
.exec( function (err, results) {
if (err) {
log('Error: ' + err.message);
callback(err);
return;
}
var array_reply = new Array();
async.forEachSeries(results,
function (result, callback) {
var reply = result.replies[result.replies_count];
array_reply.push(reply);
},callback);
callback(null, array_reply);
});
},
function (array_reply, callback) {
Model.find()
.limit(10)
.sort( {replies_count: 'desc'} )
.exec( function (err, results) {
if (err) {
callback(err);
return;
}
if (results.length > 0) {
res.render("aaa.hbs",{
models: results,
posts: array_reply
});
} else {
res.render("aaa.hbs",{
models: null,
posts: array_reply
});
}
});
}
], function (err) {
if (err) {
console.error("Error!");
return next(err);
}
})
there is callback double call (may be it causes a problem):
async.forEachSeries(results,
function (result, callback) {
var reply = result.replies[result.replies_count];
array_reply.push(reply);
},callback);
callback(null, array_reply);
I guess it might be as follows:
async.forEachSeries(results,
function (result, callback) {
var reply = result.replies[result.replies_count];
array_reply.push(reply);
},
function(err) {
callback(err, array_reply);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.