1
我寫了與MySQL的NodeJS項目,async.waterfall「回調不是一個函數」的node.js
我也實施了async.waterfall避免我最近的問題有關「回調不是一個函數'
但問題仍然存在。
這裏是我的async.waterfall
async.waterfall([
function (callback) {
hold.getEntry(function(data){
var ref = data.ref;
id = data.id;
var message = data.mess;
json = JSON.parse(message);
return callback(null, {'ref':ref, 'id':id, 'json':json});
});
},
function (dataa, callback) {
if(dataa.ref === null){
callback(null);
}else{
hold.checkPositionCandidate(dataa.ref, dataa.id, dataa.json, function(dataaa){
return callback(null, dataaa);
});
}
},
function(anoData, callback) {
console.log(anoData);
if(anoData === true){
//the err is here
hold.getVoterCount(id, json, function(votercount){
if(votercount == 0){
} else {
console.log('last function');
}
});
} else {
}
}
], function (err, results) {
// When finished execute this
});
,這是我getVotercount功能
function getVoterCount (id, callback){
pool.getConnection(function(err, con){
con.query("select total_voters as tv from pollwatcher_view where party_id = ?", [id], function(err, rows){
setTimeout(function(){
//this callback is not a function
callback(null, {'count':rows[0].tv});
console.log(rows);
}, 2000);
});
});
}
我很接近完成我的項目,但犯錯讓我挫敗。請有人幫助我。
所以你調用帶有三個參數... – elclanrs
功能...所以改變'hold.getVoterCount(ID,JSON,功能(votercount){ ...})''到'hold.getVoterCount(id,function(votercount){..})' –
@elclanrs是的,我有一個外部的json變量 – something