Reputation: 207
I'm going absolutely nuts trying to get this done with ejs. handlebars. no problem. but forcing to learn ejs.
What I am trying to do is get an error object and loop through the object and print out each message as a li.
<% if (errors !== undefined){ %>
<p>there are errors on page</p>
<% for each(error in errors){ %>
<li><%= error.msg%></li>
<% }) %>
<% } %>
I have tried many different ways to get the data to display, but I cannot seem to find my hangup. How I should get each object's msg
?
The above code is just a fraction of the code. Whole code
EDIT: Deleted information from post as it no longer pertains to my issue.
Upvotes: 2
Views: 1797
Reputation: 207
Found my error(s) [pun intended]
I was using .mapped which makes the data an object.. i needed to do .array
even with the object, the js I wanted to run does not work with objects (or at least i cant figure out how to loop through the objects specific properties).
Correct syntax for the code I wanted to run is as follows:
<% if (errors !== undefined){ %>
<p>there are errors on page</p>
<% for (const error of errors){ %>
<li><%= error.msg %> </li>
<% } %>
<% } %>
Upvotes: 2