Cannot read property 'length' of undefined 都是each item in movies著出問題怎么解決
TypeError: G:\nodejs\views\pages\index.jade:6
? ?4| .container
? ?5| .row
?> 6| each item in movies
? ?7| .col-md-2
? ?8| .thumbnail
? ?9| a(href="/movie/#{item._id}")
Cannot read property 'length' of undefined
? ?at eval (eval at <anonymous> (G:\nodejs\node_modules\jade\lib\index.js:218:8), <anonymous>:73:31)
? ?at eval (eval at <anonymous> (G:\nodejs\node_modules\jade\lib\index.js:218:8), <anonymous>:194:4)
? ?at eval (eval at <anonymous> (G:\nodejs\node_modules\jade\lib\index.js:218:8), <anonymous>:219:22)
? ?at res (G:\nodejs\node_modules\jade\lib\index.js:219:38)
? ?at Object.exports.renderFile (G:\nodejs\node_modules\jade\lib\index.js:380:38)
? ?at Object.exports.renderFile (G:\nodejs\node_modules\jade\lib\index.js:370:21)
? ?at View.exports.__express [as engine] (G:\nodejs\node_modules\jade\lib\index.js:417:11)
? ?at View.render (G:\nodejs\node_modules\express\lib\view.js:128:8)
? ?at tryRender (G:\nodejs\node_modules\express\lib\application.js:640:10)
? ?at EventEmitter.render (G:\nodejs\node_modules\express\lib\application.js:592:3)
這么寫的
2017-05-29
我已經解決了,總結出了大家的問題:
首先這里,老師沒有涉及到數據庫,所以這些數據都是“靜態的”,也就是我們自己在頁面上加的,為的就是驗證我們些的jade和相關文件。
搞清楚movie和movies的區別:movies指的是首頁的電影列表,movie指的則是詳情頁的單個電影,其實從單詞就可以搞清楚,movies是復數嘛~
因此,在看了這個視頻之后,出現property 'length' of undefined,這個錯誤的都是因為沒有在app.js中自己去定義一些數據,也就是在首頁中新建一個movies數組,或者在詳情頁中新建一個movie對象,其他的是一樣道理。
還有一點,因為這個視頻已經過去了兩年的時間,所以有些語法上會有一些錯誤,這些我都是自己去百度或者在評論區找到答案。
希望能幫助到你
2017-05-19
同樣的問題,想問一下現在有沒有找到解決的辦法,O(∩_∩)O謝謝!
2017-05-16
index.jade 頁第六行開始寫法不標準,先看一下jade的標準,前面加空格就可以
2017-05-16
看你的app.js里面,首頁和列表頁是movies,詳情頁和后臺錄入頁是movie