ejs循环实例

...

//
index page var items=[{title:"文章1"},{title:"文章2"}]; app.get('/',function(req,res){ res.render('index',{title:'电影首页',items:items}); });

...

对应ejs

<html>
<head>
<title>my ejs template</title>
</head>

<body>
    <p>Hi <%= title %></p>
    <p>文章列表</p>
    <ul>
        <% items.forEach(function(item){%>
                <li><%=item.title %></li>
            <% }) %>
    </ul>
</body>
</html>

预览图

原文地址:https://www.cnblogs.com/tinyphp/p/4942131.html