【问题标题】:Pug: Cannot read property 'title' of undefined哈巴狗:无法读取未定义的属性“标题”
【发布时间】:2020-11-28 01:29:18
【问题描述】:

我想将一个数组传递给一个 pug 视图并通过迭代它来构造视图,但是当我加载视图时出现错误。

PUG 视图

include includes/header.pug
body.index
    include includes/nav-bis.pug
    .hero
        .hero-body
            .container
                .box
                    for post in posts
                        h1= posts[post].title
                        p= posts[post].content.substring(0, 100)+" ..."
                            a(href="/posts/" + posts[post].title) Read More

app.js

app.get('/blog', function(req, res) {
    console.log(posts);
    res.render('blog', {posts: posts});
});

【问题讨论】:

    标签: node.js pug


    【解决方案1】:

    您以错误的方式调用该帖子。试试下面的代码:

    h1= post.title
    

    【讨论】:

    • 是的,我现在才弄清楚自己!我需要休息一下?
    猜你喜欢
    • 2019-12-17
    • 1970-01-01
    • 2018-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-25
    • 1970-01-01
    相关资源
    最近更新 更多