我知道它必须进入 <% %> 内部,但我不确定它是否与典型的 forEach/for 循环有很大不同。 EJS 站点上的文档非常有限,所以我来到这里。
<% include ../../partials/header %>
<body>
<main>
<h1>List of all quotes</h1>
<ul>
<li> <!-- for loop goes here, inside flounder -->
<%
all quote stuff goes here
author
content
wrap it in a link to its quote page
</li>
</ul>
</main>
</body>
</html>
最佳答案
这是关于嵌入式js的示例:
<ul>
<% for(var i=0; i<supplies.length; i++) {%>
<li><%= supplies[i] %></li>
<% } %>
</ul>
这就是我所做的:
<% include ../../partials/header %> <
<body>
<main>
<h1>List of all quotes</h1>
<ul>
<% for(var i = 0; i < author.length; i++) {
<li><%= author[i] %></li>
<% } %>
<% for(var i = 0; i < content.length; i++) {
<li><%= content[i] %></li>
<% } %>
</ul>
</main>
</body>
</html>
关于javascript - 如何在 EJS 中执行 for 循环/foreach ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49264980/