javascript - "callback is not a function"Node.js

标签 javascript node.js asynchronous callback

我有一个用 NodeJs 和 mysql 编写的项目,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){
                if(votercount == 0){
                } else {
                    console.log('last function');
                }
            });

但是您的 getVoterCount 函数仅使用 2 个预期参数定义。我建议尝试只传递 2 个参数:

hold.getVoterCount(id, function(votercount){
            if(votercount == 0){
            } else {
                console.log('last function');
            }
        });

关于javascript - "callback is not a function"Node.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35762125/

相关文章:

javascript - 缺少 : after property id when minifying with yuicompressor

javascript - 错误 : connect ECONNREFUSED Node. js、Heroku、Mysql

javascript - 如何让 Mongoose 列出集合中的所有文档?判断集合是否为空?

javascript - delete object[element] 不会删除,而是将其设置为 null ....如何删除它而不是使其为 null?

javascript - 如何将函数传递给 nodejs-express 中的 express-handlebars?

javascript - 仅在 Dropbox 中存储文件时,Datastore 和核心 API 之间的区别?

javascript - 使用 jQuery 从文本变量中选择带有选择器的标签

javascript - indexedDB idb 库 - 插入多条记录

asynchronous - Dart 在异步修改主体上的 runZoned() 行为

java - 同时运行 Void CompletionStage 但忽略结果