【发布时间】:2016-06-16 04:27:25
【问题描述】:
我有一个用 mysql 用 NodeJs 编写的项目,async.waterfall
我还实现了 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);
});
});
}
我非常接近完成我的项目,但那个错误让我感到沮丧。请有人帮助我。
【问题讨论】:
-
所以你用三个参数调用函数...
-
...所以把
hold.getVoterCount(id, json, function(votercount){...})改成hold.getVoterCount(id, function(votercount){..}) -
@elclanrs 是的,我在外面有一个 json 变量
-
@NikolayErmakov 你是我的救星!我没看到。谢谢!
标签: javascript node.js asynchronous callback