【问题标题】:blank bootstrap cards are showing before my db images在我的数据库图像之前显示空白引导卡
【发布时间】:2022-01-17 17:04:06
【问题描述】:

我有一个使用 nodejs、express 和 mongodb 的在线商店网页,所以我已将图片网址、标题、描述...上传到我的数据库中 但问题是,在网页上,每张图片之前都会显示 2 张黑卡,我将向你们展示以下代码:
看看下面的图片

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;

index.hbs

{{# each products}}
<div class="d-flex justify-content-between mt-3">
   {{# each this}}
   <div class="card" style="width: 18rem;">
      <img class="card-img-top" src="{{this.imagePath}}" alt="image">
      <div class="card-body">
         <h5 class="card-title">{{this.title}}</h5>
         <p class="card-text">{{this.description}}</p>
         <div class="d-flex justify-content-between align-items-center">
            <div class="price">{{this.price}} $</div>
            <a href="#" class="btn btn-primary"><i class="fa fa-shopping-cart" aria-hidden="true"></i> Buy</a>
         </div>
      </div>
   </div>
   {{/each}}
</div>
{{/each}}

以下错误: Click for image

【问题讨论】:

标签: javascript node.js mongodb express hbs


【解决方案1】:

仔细检查你上传图片和加载图片的来源,你可以在浏览器>网络中使用开发者工具,检查图片是否加载,是否包含有关url、状态、有效负载等信息。

【讨论】:

  • 我的数据库中有 7 张图片,这 7 张图片显示在最后一列,其他卡片没有任何信息,它们应该为空或根本不显示
  • @OmarDakelbab 你能在codesandbox上发帖吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-03
  • 1970-01-01
相关资源
最近更新 更多