本文介绍了.get()需要回调函数但得到一个[对象未定义]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用mongoose。
I am working with mongoose.
我在routes.js中写了以下代码
I wrote the following code in routes.js
var docs = require('../app/controllers/genericController');
app.post('/newdoc', docs.createMainDoc);
app.get('/listdoc', docs.listDocs);
和genericController:
and in 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
。这就是为什么未定义
。
You have docs.listDocs
instead of docs.listDoc
. That's why it's undefined
.
app.get('/listdoc', docs.listDoc/*s*/);
这篇关于.get()需要回调函数但得到一个[对象未定义]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!