node.js 遍历报错

extends ../layout

block content
	.container
		.row
			each item in movies
				.col-md-2
					.thumbnail
						a(href="/movie/#{item._id}")
							img(src="#{item.poster}", alt="#{item.title}")
						.caption
							h3 #{item.title}
							p: a.btn.btn-primary(href = "/movie/#{item._id}", role ="button")
								观看预告片

为什么第6行一只在报错呢,错误贴在下方:

TypeError: E:\NodeMovie\imooc\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> (E:\NodeMovie\imooc\node_modules\jade\lib\index.js:218:8), <anonymous>:103:31)
   at eval (eval at <anonymous> (E:\NodeMovie\imooc\node_modules\jade\lib\index.js:218:8), <anonymous>:224:4)
   at eval (eval at <anonymous> (E:\NodeMovie\imooc\node_modules\jade\lib\index.js:218:8), <anonymous>:240:22)
   at res (E:\NodeMovie\imooc\node_modules\jade\lib\index.js:219:38)
   at Object.exports.renderFile (E:\NodeMovie\imooc\node_modules\jade\lib\index.js:380:38)
   at Object.exports.renderFile (E:\NodeMovie\imooc\node_modules\jade\lib\index.js:370:21)
   at View.exports.__express [as engine] (E:\NodeMovie\imooc\node_modules\jade\lib\index.js:417:11)
   at View.render (E:\NodeMovie\imooc\node_modules\express\lib\view.js:128:8)
   at tryRender (E:\NodeMovie\imooc\node_modules\express\lib\application.js:640:10)
   at EventEmitter.render (E:\NodeMovie\imooc\node_modules\express\lib\application.js:592:3)

慕勒4207555
浏览 1321回答 1
1回答

weibo_迪亚波罗1982_6_0

你没有传movies的值到index.jaderes.render('index',{     title: '你的title',     movies: [{...}] });movies的值应该是从mongodb查询出来的
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Node.js