我编写了这段代码,并得到了玉器迭代的错误:无法读取未定义的“长度”属性,试图将数据发送到哈巴狗视图,并且由于错误而无法读取
app.get('/about', (req, res)=>{
var partners =[
{ "name":"Name1", "image": "img1.jpg" },
{ "name": "Name2", "image": "img2.jpg" },
{"name":"Name3", "image": "img3.jpg" }
];
let lang = getLang(req, res, ['about']);
res.render('about', {partners , ...lang});
});
extends layout
block content
.subhead
h2= about.title
.content.about
for item in about.team
div.team
h3
span= item[0]
small= item[1]
p= item[2]
each partner in partners
li.swiper-slide
img(src=partner.image, alt=partner.name)
答案 0 :(得分:1)
这是当pug模板未正确传递变量时出现的错误。我敢打赌,您的节点服务器没有正确解释您的“新” JSON语法。
使用此更基本的JSON,它将起作用:
res.render('about', {
"partners": partners,
"lang": lang
});