How to array of objects in template ejs?

后端 未结 4 1462
遥遥无期
遥遥无期 2021-01-12 18:57

I have a results variable that is an array of objects. I carry the results variable from my javascript file to my main route file. I am trying to render my page to display l

相关标签:
4条回答
  • 2021-01-12 19:25
    <ul>
        <% for(var i=0; i<results.length; i++) { %>
            <li>
                <%= results[i] %>
            </li>
        <% } %>
    </ul>
    
    0 讨论(0)
  • 2021-01-12 19:28

    This will show list of id of your results, just change _id by your property of objects as you want to show.

     <ul> 
      <% results.map((result)=>{ %>
        <li>
            <%= result._id %>
        </li>
      <% }) %>
     </ul>
    
    0 讨论(0)
  • 2021-01-12 19:36

    My answer is as follows. I changed one line from the answer by other person.

    <ul>
    <%for (var result in results){%>
      <li><%=result%>:<%=results[result]%></li>    
      <%}%>
    </ul>
    
    0 讨论(0)
  • 2021-01-12 19:38

    Try this:

    <ul>
         <%for (var result in results){%>
                    <li><%=result%></li>    
            <%}%>
    </ul>
    
    0 讨论(0)
提交回复
热议问题