I'm having trouble printing out a simple for each ment loop with _.template.
<% _.each([ments], function(i) { %> <p><%= i %></p> <% }); %>
prints [object Object]
<% _.each([ments], function(i) { %> <p><%= JSON.stringify(i) %></p> <% }); %>
prints:
[{"ment":"Mauris quis leo at diam molestie sagittis.","id":263,"observation_id":25}]
What I've tried so far:
<% _.each([ments], function(i) { %> <p><%= iment %></p> <% }); %>
blank
<% _.each([ments], function(i) { %> <p><%= i.get('ment') %></p> <% }); %>
Uncaught TypeError: Object [object Array] has no method 'get'
<% _.each([ments], function(i) { %> <p><%= ment %></p> <% }); %>
blank
I'm having trouble printing out a simple for each ment loop with _.template.
<% _.each([ments], function(i) { %> <p><%= i %></p> <% }); %>
prints [object Object]
<% _.each([ments], function(i) { %> <p><%= JSON.stringify(i) %></p> <% }); %>
prints:
[{"ment":"Mauris quis leo at diam molestie sagittis.","id":263,"observation_id":25}]
What I've tried so far:
<% _.each([ments], function(i) { %> <p><%= i.ment %></p> <% }); %>
blank
<% _.each([ments], function(i) { %> <p><%= i.get('ment') %></p> <% }); %>
Uncaught TypeError: Object [object Array] has no method 'get'
<% _.each([ments], function(i) { %> <p><%= ment %></p> <% }); %>
blank
Share Improve this question asked Apr 17, 2013 at 21:36 ObviousCatObviousCat 5051 gold badge5 silver badges17 bronze badges 2-
And what does
ments
contains? That's basically what's important here. – Loamhoof Commented Apr 17, 2013 at 21:45 -
And why are you wrapping
ments
in an array? I would assume that it's already an array, right? – idbehold Commented Apr 17, 2013 at 22:04
1 Answer
Reset to default 15Assuming ments is an array on your model:
<% _.each(ments, function(ment) { %>
<p><%= ment.ment %></p>
<% }); %>