我正在和 Mongoose 一起工作。
我在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);
}
});
};
Bu我收到错误消息:
.get() requires callback functions but got a [object Undefined]
怎么解决呢?
最佳答案
您有docs.listDocs
而不是docs.listDoc
。这就是为什么是undefined
的原因。
app.get('/listdoc', docs.listDoc/*s*/);
关于javascript - .get()需要回调函数,但有一个[object Undefined],我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18616074/