我写了一个小玉石脚本
ul.sidebar-nav
each(record in #{records})
li
a(href='#') #{record.sender}
我将记录数组对象传递给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
答案 0 :(得分:0)
each(record in #{records})
你不想在这里解析records
;你只想将它用作数组。只需使用
each(record in records)
它应该有用。
答案 1 :(得分:0)
只需使用:
each record in records