回调参数无法访问

时间:2014-12-02 21:44:10

标签: node.js express

我刚刚开始摆弄节点,我遇到了问题

mongoose = require "mongoose"
CalendarSchema = new mongoose.Schema
name: String

Calendar = mongoose.model('Calendar', CalendarSchema)

router = express.Router() # get an instance of the express Router

# Routes
# 
router.get "/calendars", (req, res) ->
  Calendar.find(error, calendars) ->
    if error
      res.send(error) 
    res.json(calendars)
    return

app.use('/api', router)

但是,使用这段代码,我收到错误

ReferenceError: error is not defined

这是指Calendar.find方法中的回调参数,为什么会这样?

0 个答案:

没有答案