.get()需要回调函数,但得到了一个[object Undefined]

.get() requires callback functions but got a [object Undefined]

本文关键字:一个 Undefined object 回调 函数 get      更新时间:2023-09-26

我正在使用猫鼬。

我在routes.js 中编写了以下代码

var docs = require('../app/controllers/genericController');
    app.post('/newdoc', docs.createMainDoc);
    app.get('/listdoc', docs.listDocs);

和在genericController中:

exports.listDoc = function(req, res) {
    var Model = mongoose.model(req.model); //i dont know, if this is defined or undefined. Actually i am not able to check it. Even if i comment whole body of this exports.listDoc, then also i get the same error. just assume here that here i am getting model.
    Model.find(function(err, models) {
        if (err) {
            res.render('error', {
                status: 500
            });
        } else {
            res.jsonp(models);
        }
    });
};

但是我得到了错误:

.get() requires callback functions but got a [object Undefined]

如何解决?

您有docs.listDocs而不是docs.listDoc。这就是为什么它是undefined

app.get('/listdoc', docs.listDoc/*s*/);