无法读取未定义哈巴狗的属性“长度" [英] Cannot read property 'length' of undefined pug

查看:44
本文介绍了无法读取未定义哈巴狗的属性“长度"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了这段代码,但出现错误 jade 迭代:无法读取未定义的属性 'length' 试图将数据发送到 pug 视图,我无法读取它,因为它是错误的

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)

推荐答案

这是当 pug 模板没有正确传递变量时出现的错误.我敢打赌您的节点服务器没有正确解释您的新"JSON 语法.

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.

改用这个更基本的 JSON,它会起作用:

Use this more basic JSON instead and it will work:

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

这篇关于无法读取未定义哈巴狗的属性“长度"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆