I am trying to iterate through an array of objects using express.
This is the iteration in Pug.
each thing in things
div.Test
div= thing.name
div= thing.id
And this is how the Express route looks like.
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,
});
});
While the iteration works, I can see that the console spits out these error messages.
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)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…