[英]Underscore template display array of objects via _.each
我在使用_.template打印每個注釋循環的簡單時遇到問題。
<% _.each([comments], function(i) { %> <p><%= i %></p> <% }); %>
打印[object Object]
<% _.each([comments], function(i) { %> <p><%= JSON.stringify(i) %></p> <% }); %>
打印:
[{"comment":"Mauris quis leo at diam molestie sagittis.","id":263,"observation_id":25}]
到目前為止我嘗試過的:
<% _.each([comments], function(i) { %> <p><%= i.comment %></p> <% }); %>
空白
<% _.each([comments], function(i) { %> <p><%= i.get('comment') %></p> <% }); %>
未捕獲的TypeError:對象[object Array]沒有方法'get'
<% _.each([comments], function(i) { %> <p><%= comment %></p> <% }); %>
空白
假設注釋是模型上的數組:
<% _.each(comments, function(comment) { %>
<p><%= comment.comment %></p>
<% }); %>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.