Javascript 无法读取Jade中未定义的属性
我写了一个很小的玉书Javascript 无法读取Jade中未定义的属性,javascript,node.js,pug,Javascript,Node.js,Pug,我写了一个很小的玉书 ul.sidebar-nav each(record in #{records}) li a(href='#') #{record.sender} 我正在将一个records数组对象传递给jade模板,但是,record没有定义。有人能解释一下我为什么会犯这个错误吗 以下是全部错误: /home/ritesh/Sample/Sample1/Sample/views/index.jade:9 7| each(record in #{records}
ul.sidebar-nav
each(record in #{records})
li
a(href='#') #{record.sender}
我正在将一个records数组对象传递给jade模板,但是,record
没有定义。有人能解释一下我为什么会犯这个错误吗
以下是全部错误:
/home/ritesh/Sample/Sample1/Sample/views/index.jade:9 7| each(record in #{records}) 8| li > 9| a(href='#') #{record.sender} 10| Cannot read property 'sender' of undefined
TypeError: /home/ritesh/Sample/Sample1/Sample/views/index.jade:9
7| each(record in #{records})
8| li
> 9| a(href='#') #{record.sender}
10|
Cannot read property 'sender' of undefined
at eval (eval at <anonymous> (/home/ritesh/Sample/Sample1/Sample/node_modules/jade/lib/index.js:216:8), <anonymous>:83:49)
at eval (eval at <anonymous> (/home/ritesh/Sample/Sample1/Sample/node_modules/jade/lib/index.js:216:8), <anonymous>:110:22)
at res (/home/ritesh/Sample/Sample1/Sample/node_modules/jade/lib/index.js:217:38)
at Object.exports.renderFile (/home/ritesh/Sample/Sample1/Sample/node_modules/jade/lib/index.js:360:38)
at View.exports.renderFile [as engine] (/home/ritesh/Sample/Sample1/Sample/node_modules/jade/lib/index.js:350:21)
at View.render (/home/ritesh/Sample/Sample1/Sample/node_modules/express/lib/view.js:93:8)
at EventEmitter.app.render (/home/ritesh/Sample/Sample1/Sample/node_modules/express/lib/application.js:530:10)
at ServerResponse.res.render (/home/ritesh/Sample/Sample1/Sample/node_modules/express/lib/response.js:933:7)
at /home/ritesh/Sample/Sample1/Sample/routes/index.js:13:7
at /home/ritesh/Sample/Sample1/Sample/node_modules/mongojs/node_modules/mongodb/lib/mongodb/cursor.js:172:16
/home/ritesh/Sample/Sample1/Sample/views/index.jade:9 7|each(记录在#{records})8|li>9|a(href='#')#{record.sender}10|无法读取未定义的属性“sender”
TypeError:/home/ritesh/Sample/Sample1/Sample/views/index.jade:9
7 |每个(在#{records}中记录)
8 |里
>9 | a(href='#')#{record.sender}
10|
无法读取未定义的属性“发件人”
评估时(评估时(/home/ritesh/Sample/Sample1/Sample/node_modules/jade/lib/index.js:216:8),:83:49)
评估时(评估时(/home/ritesh/Sample/Sample1/Sample/node_modules/jade/lib/index.js:216:8),:110:22)
在res(/home/ritesh/Sample/Sample1/Sample/node\u modules/jade/lib/index.js:217:38)
在Object.exports.renderFile(/home/ritesh/Sample/Sample1/Sample/node\u modules/jade/lib/index.js:360:38)
在View.exports.renderFile[作为引擎](/home/ritesh/Sample/Sample1/Sample/node_modules/jade/lib/index.js:350:21)
在View.render(/home/ritesh/Sample/Sample1/Sample/node_modules/express/lib/View.js:93:8)
位于EventEmitter.app.render(/home/ritesh/Sample/Sample1/Sample/node_modules/express/lib/application.js:530:10)
在ServerResponse.res.render(/home/ritesh/Sample/Sample1/Sample/node_modules/express/lib/response.js:933:7)
at/home/ritesh/Sample/Sample1/Sample/routes/index.js:13:7
在/home/ritesh/Sample/Sample1/Sample/node_modules/mongojs/node_modules/mongodb/lib/mongodb/cursor.js:172:16
你不想在这里解析记录
;您只想将其用作数组。只用
each(record in records)
它应该可以工作。只要使用:
each record in records
尝试记录中的每条记录,记住记录应该是一个数组。
each record in records