简体   繁体   中英

How to display nested field mongodb in EJS

I am trying to display a field that contains a image link and that is nested in my collection in MongoDB to ejs. However when i try to display it EJS can't find the image.. I am using the User schema so when I write: <%=user.slot1img%> then it won't be able to find that resource.

The structure is like this for each item:

 Inventory: [ { Item1: [ { slot1img: "", slot1text: "", } ],

So how could I show a item if its nested in mongodb to the EJS file?

use nested for loop

inventory.forEach(i => {
    i.Item1.forEach(j => {
       <%= j.slot1.img %>
    })
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM