如何解决迭代数组时“无法读取未定义的属性‘长度’”
我正在尝试使用 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 举报,一经查实,本站将立刻删除。