【问题标题】:error using handlebars #each with node and express使用带有节点和快递的把手#each 时出错
【发布时间】:2020-05-13 02:03:47
【问题描述】:

Handlebars:访问已被拒绝解析属性“title”,因为它不是其父级的“自己的属性”。 您可以添加运行时选项来禁用检查或此警告: 详情见http://localhost:8080/api-reference/runtime-options.html#options-to-control-prototype-access Handlebars:访问已被拒绝解析属性“描述”,因为它不是其父级的“自己的属性”。

【问题讨论】:

标签: node.js express handlebars.js


【解决方案1】:

这是一个关于这个问题的很好的讨论,并提供了一些关于如何解决它的建议,link。我用 yarn upgrade-interactive --latest 升级了我的 jest 包,这为我解决了这个问题。

【讨论】:

    【解决方案2】:
    // Idea Index Page
    app.get('/ideas', (req, res) => {
      Test1.find({})
        .sort({date:'desc'})
        .lean()
        .then(ideas => {
          res.render('ideas/index', {
            ideas1: ideas
          });
        });
    });
    

    使用.lean(),它可以正常工作。

    【讨论】:

      【解决方案3】:

      下载包 npm install @handlebars/allow-prototype-access 并将其导入您的 app.js const {allowInsecurePrototypeAccess} = require('@handlebars/allow-prototype-access')

      到 app.js 中的 app.engine() 使用这个语法:

      app.engine('handlebars', exphbs({ defaultLayout: 'main', handlebars: allowInsecurePrototypeAccess(Handlebars) },
      ));
      app.set('view engine', 'handlebars',);

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-07-15
        • 2012-09-04
        • 1970-01-01
        • 1970-01-01
        • 2022-06-24
        • 1970-01-01
        相关资源
        最近更新 更多