问题描述
我正在尝试使用 express 遍历对象数组。
这是 Pug 中的迭代。
each thing in things
div.Test
div= thing.name
div= thing.id
这就是 Express 路线的样子。
app.get("/",async (req,res) => {
const things = [
{
name: "Foo bar",id: 1,},{
name: "Another foo bar",id: 2,{
name: "Here we go again",id: 7888822,];
res.render("index",{
things: things,});
});
在迭代过程中,我可以看到控制台会吐出这些错误消息。
Cannot read property 'length' of undefined
at eval (eval at wrap (/this/is/not/the/real/path/node_modules/pug-runtime/wrap.js:6:10),<anonymous>:97:32)
at eval (eval at wrap (/this/is/not/the/real/path/node_modules/pug-runtime/wrap.js:6:10),<anonymous>:128:4)
at template (eval at wrap (/this/is/not/the/real/path/node_modules/pug-runtime/wrap.js:6:10),<anonymous>:131:7)
at Object.exports.renderFile (/this/is/not/the/real/path/node_modules/pug/lib/index.js:452:38)
at Object.exports.renderFile (/this/is/not/the/real/path/node_modules/pug/lib/index.js:442:21)
at View.exports.__express [as engine] (/this/is/not/the/real/path/node_modules/pug/lib/index.js:491:11)
at View.render (/this/is/not/the/real/path/node_modules/express/lib/view.js:135:8)
at tryRender (/this/is/not/the/real/path/node_modules/express/lib/application.js:640:10)
at Function.render (/this/is/not/the/real/path/node_modules/express/lib/application.js:592:3)
at ServerResponse.render (/this/is/not/the/real/path/node_modules/express/lib/response.js:1012:7)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)