javascript - Underscore template display array of objects via _.each -
i'm having trouble printing out simple each comment loop _.template.
<% _.each([comments], function(i) { %> <p><%= %></p> <% }); %>
prints [object object]
<% _.each([comments], function(i) { %> <p><%= json.stringify(i) %></p> <% }); %>
prints:
[{"comment":"mauris quis leo @ diam molestie sagittis.","id":263,"observation_id":25}]
what i've tried 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
assuming comments array on model:
<% _.each(comments, function(comment) { %> <p><%= comment.comment %></p> <% }); %>
Comments
Post a Comment