Warm tip: This article is reproduced from serverfault.com, please click

node.js-哈巴狗:无法读取未定义的属性“标题”

(node.js - Pug: Cannot read property 'title' of undefined)

发布于 2020-11-28 01:29:18

我想将数组传递给哈巴狗视图,并通过对其进行迭代来构造视图,但是在加载视图时出现错误。

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});
});
Questioner
Quentin C
Viewed
11
IRSHAD 2020-11-28 09:44:22

你以错误的方式致电该职位。试试下面的代码:

h1= post.title