簡體   English   中英

如何在html上顯示來自貓鼬的圖像

[英]How to display images form a mongoose on html

您好,我正在使用 node.js、express 和 javascript 開發 Web 應用程序。 我真的很困惑如何顯示從貓鼬返回的圖像集合。

      imageModel.find().where("createdBy", username).
        exec(function(err, imagesByUser) {
        if (err) { console.error(err); return; }
        console.log("User at getUser is: "+ imagesByUser);
        if (imagesByUser != null) callback(imagesByUser);
      });

然后我嘗試將imagesByUser從我的index.js發送到jade文件我嘗試了多種方法將圖像作為json中的數組傳遞

res.json(images);

我只是想知道如何在 jade 文件中迭代 json 數組並顯示這些圖像。 謝謝 ! 拉里

您的圖像必須在另一台服務器(如 S3)上,因此圖像只是您發送到模板的 URL,不需要傳遞 json。

res.render('template.html', {imageByUsers: imageByUsers})

在模板上使用 Swig.js

<img src="{{ imageByUsers.image }}" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM