我遵循 MCV 方法来开发我的应用程序。我遇到一个问题,我不知道参数是如何传递给回调函数的。
动物.js(模型)
var mongoose = require('mongoose')
, Schema = mongoose.Schema
var animalSchema = new Schema({ name: String, type: String });
animalSchema.statics = {
list: function(cb) {
this.find().exec(cb)
}
}
mongoose.model('Animal', animalSchema)
动物.js(控制器)
var mongoose = require('mongoose')
, Animal = mongoose.model('Animal')
exports.index = function(req, res) {
Animal.list(function(err, animals) {
if (err) return res.render('500')
console.log(animals)
}
}
我的问题来了:为什么模型中的“列表”可以只执行回调而不传递任何参数?错误和动物实际上来自哪里?
我想我可能会错过一些与 node.js 和 mongoose 中的回调相关的概念。如果您能提供一些解释或指出一些材料,非常感谢。