【问题标题】:error using handlebars #each with node and express使用带有节点和快递的把手#each 时出错
【发布时间】:2020-05-13 02:03:47
【问题描述】:
【问题讨论】:
标签:
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',);