亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

關于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對象的

http://img1.sycdn.imooc.com//5626e4af0001e29d06770323.jpg

請問render怎么能讀取到外面的movie對象?

正在回答

舉報

0/150
提交
取消
node+mongodb 建站攻略(一期)
  • 參與學習       91827    人
  • 解答問題       921    個

帶你完整實現一個從前端到后端的項目,初中級前端開發工程師必學課程

進入課程

關于JS 作用域的問題

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號