车把:已拒绝访问以解析属性"imagePath",因为它不是其父级的"own property"



我无法将保存的数据从产品播种机正确发送到商店

看起来像这样 https://prnt.sc/t10v00

我想要我来到页面的数据中的图像和标题

在我的终端中说/////车把:已拒绝访问以解析属性"所有权",因为它不是其父级的"自有财产">

{{# each products}}
<div class="row">
{{# each this}}
<div class="col-sm-6 col-md-4">
<div class="thumbnail">
<img src="{{this.imagePath}}" alt="..." class = "img-responsive">
<div class="caption">
<h3 align="center">{{this.title}}</h3>
<p class="description">{{this.description}}</p>
<div class="clearfix">
<div class="price pull-left">€{{this.price}}<ahref="#" style="float:right"class="btn btn-primary pull-right" role="button">Add cart</a> </div>
</div>
</div>
</div>
{{/each}}
</div>
{{/each}}

index.js
var express = require('express');
var router = express.Router();
var Product = require('../models/product');
/* GET home page. */
router.get('/', function(req, res, next) {
Product.find(function(err, docs) {
var productChunks = [];
var chunkSize = 3;
for (var i = 0; i < docs.length; i += chunkSize) {
productChunks.push(docs.slice(i, i + chunkSize));
}
res.render('shop/index', { title: 'Shopping Cart', products: productChunks });
});
});
module.exports = router;

有人可以帮助我吗?

"express-handlebars": "^3.0.0"

使用了这个版本。 成功了。 它为较新版本提供相同的输出。

遵循给定的以下语法:

dbName.find({}).lean()
// execute query
.exec(function(error, body) {
//Execute you code
});

这段代码对我有用:

const Handlebars = require('handlebars');
const expressHandlebars=require('express-handlebars');
const { allowInsecurePrototypeAccess } = require('@handlebars/allow-prototype-access');

// view engine setup
app.engine('.hbs', expressHandlebars({ handlebars: allowInsecurePrototypeAccess(Handlebars) ,defaultLayout: 'layout', extname: '.hbs'}));
//app.set('views', path.join(__dirname, 'views'));
app.set('view engine', '.hbs');
I've added the following code and it's working fine. You need to add the runtimeoptions here. 
const {engine} =  require('express-handlebars');


app.engine('.hbs', engine({
defaultLayout: 'main', 
extname: 'hbs',
runtimeOptions: {
allowProtoPropertiesByDefault: true,
allowProtoMethodsByDefault: true
}
}));
app.set('view engine', '.hbs');
I have used the above code to implement the .hbs template engine.

相关内容

最新更新