我为库存做了一个展示页面
<% inventory.products.forEach(function(product) { %>
<div class="card">
<img src="<%= product.image %>" alt="" class="card-img-top" />
<div class="card-body">
<h5 class="card-title">
<%= product.name %>
</h5>
</div>
</div>
<% }) %>
但是页面没有显示任何产品图片和名称(我的页面和数据库的截图)
我的库存数据库的代码是:
let mongoose = require("mongoose");
let inventorySchema = new mongoose.Schema({
id: {
type: mongoose.Schema.Types.ObjectId,
},
author: {
id: {
type: mongoose.Schema.Types.ObjectId,
ref: "User",
},
username: String,
},
products: [
{
type: mongoose.Schema.Types.ObjectId,
ref: "Product",
},
],
});
module.exports = mongoose.model("Inventory", inventorySchema);
我认为您不应该封闭映像路径(<%=product.image%>) 用引号表示。 请尝试删除引号。