Obv*_*Cat 3 javascript backbone.js underscore.js
我在使用_.template打印每个注释循环的简单时遇到问题.
<% _.each([comments], function(i) { %> <p><%= i %></p> <% }); %>
Run Code Online (Sandbox Code Playgroud)
打印[object Object]
<% _.each([comments], function(i) { %> <p><%= JSON.stringify(i) %></p> <% }); %>
Run Code Online (Sandbox Code Playgroud)
打印:
[{"comment":"Mauris quis leo at diam molestie sagittis.","id":263,"observation_id":25}]
Run Code Online (Sandbox Code Playgroud)
到目前为止我尝试过的:
<% _.each([comments], function(i) { %> <p><%= i.comment %></p> <% }); %>
Run Code Online (Sandbox Code Playgroud)
空白
<% _.each([comments], function(i) { %> <p><%= i.get('comment') %></p> <% }); %>
Run Code Online (Sandbox Code Playgroud)
未捕获的TypeError:对象[object Array]没有方法'get'
<% _.each([comments], function(i) { %> <p><%= comment %></p> <% }); %>
Run Code Online (Sandbox Code Playgroud)
空白
Sco*_*leo 15
假设注释是模型上的数组:
<% _.each(comments, function(comment) { %>
<p><%= comment.comment %></p>
<% }); %>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10834 次 |
| 最近记录: |