哈巴狗:无法读取未定义的 属性 'title'

Pug: Cannot read property 'title' of undefined

我想将一个数组传递给哈巴狗视图并通过遍历它来构造视图,但是当我加载视图时出现错误。

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});
});

您调用 post 的方式有误。试试下面的代码:

h1= post.title