简体   繁体   English

TypeError:undefined不是node.js / express.js中的函数

[英]TypeError: undefined is not a function in node.js / express.js

I got the following error: TypeError: undefined is not a function 我收到以下错误:TypeError:undefined不是一个函数

callback(null, array_reply, threadResults); 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);
        });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 500 TypeError:在express.js,node.js中不是字符串或缓冲区 - 500 TypeError: Not a string or buffer in express.js,node.js Sequelize.js/Node.js/Express.js:Tasks.findAll() 返回一个 TypeError:Cannot read property 'findAll' of undefined - Sequelize.js/Node.js/Express.js: Tasks.findAll()returns a TypeError:Cannot read property 'findAll' of undefined Node.js Express:TypeError:对象不是函数 - Node.js Express: TypeError: object is not a function Azure 上的 SQL Server 连接到 REST API Express.js/Node.js [TypeError: req.sql is not a function] - SQL Server on Azure connected to REST API Express.js/Node.js [TypeError: req.sql is not a function] 为什么我的 kafkajs 客户端 (Node.js/express.js) 在获取主题元数据时抛出“TypeError:topics.forEach 不是函数”? - Why is my kafkajs client (Node.js/express.js) throwing 'TypeError: topics.forEach is not a function' while fetching topics metadata? TypeError:undefined不是Node.js中的函数 - TypeError: undefined is not a function in Node.js Node.js和mongodb TypeError:undefined不是函数 - Node.js and mongodb TypeError: undefined is not a function TypeError:undefined不是函数-Node.js&MongoDB - TypeError: undefined is not a function - Node.js & MongoDB Node.js TypeError:未定义不是函数 - Node.js TypeError: undefined is not a function 使用express.js和节点0.10.29的未定义帖子 - Undefined Post with express.js and node 0.10.29
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM