Cannot read property 'length' of undefined pug

≡放荡痞女 提交于 2019-12-24 21:06:13

问题


I wrote this code and I get the error jade iteration: cannot read property 'length' of undefined trying to send data to pug view and i cannot read it because it's wrong

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)

回答1:


That's the error that comes up when the pug template isn't being passed the variable properly. I'd bet that your node server isn't properly interpreting your "new" JSON syntax.

Use this more basic JSON instead and it will work:

res.render('about', {
  "partners": partners,
  "lang": lang
});


来源:https://stackoverflow.com/questions/57438886/cannot-read-property-length-of-undefined-pug

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!