Reputation: 505
I'm having trouble printing out a simple for each comment loop with _.template.
<% _.each([comments], function(i) { %> <p><%= i %></p> <% }); %>
prints [object Object]
<% _.each([comments], function(i) { %> <p><%= JSON.stringify(i) %></p> <% }); %>
prints:
[{"comment":"Mauris quis leo at diam molestie sagittis.","id":263,"observation_id":25}]
What I've tried so far:
<% _.each([comments], function(i) { %> <p><%= i.comment %></p> <% }); %>
blank
<% _.each([comments], function(i) { %> <p><%= i.get('comment') %></p> <% }); %>
Uncaught TypeError: Object [object Array] has no method 'get'
<% _.each([comments], function(i) { %> <p><%= comment %></p> <% }); %>
blank
Upvotes: 3
Views: 11499
Reputation: 3684
Assuming comments is an array on your model:
<% _.each(comments, function(comment) { %>
<p><%= comment.comment %></p>
<% }); %>
Upvotes: 15