简体   繁体   中英

How to create and insert div element to .ejs (node.js, express, ejs)

I have an array of objects and I need to create div elements while iterating over it and then render it using ejs. I'm using node.js express and ejs. How can I create divs and inject it to ejs?

you can use in ejs like that, it's simple for function:

In ejs:

<% for (var i = 0; i < products.length; i ++) { %>

 <a href="/product/<%=products[i].product_id%>"> 
 <b> <%=products[i].product_id%> </b> 
<% } %>

In js file:

router.get('/', function(req, res, next) {
    res.render('sell',{ products: array})
});

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