關于JS 作用域的問題
app.get('/movie/:id', function (req, res) {
? ? var id = req.params.id
? ? console.log(id + "b")
? ? Movie.findById(id, function(err, movie) {? ? ? ??
????//console.log(movie.title)
? ? ?res.render('detail', {
? ? ? ? ? ? title: 'imooc' + movie.title,
? ? ? ? ? ? movie: movie
? ? ? ? })
? ? })
})
這段代碼報錯:
TypeError: cannot read property 'title' of undefined.
然而我render上的那個console.log是能正常輸出這個movie對象的
請問render怎么能讀取到外面的movie對象?