soc*_*ngh 2 javascript coffeescript underscore.js eco
我确定我做的很简单,但似乎无法找到解释.我的模板中有以下行,它不会向html输出打印任何值:
<%= _.each(@place.get("hash"),(count, tag) -> "#{tag} ") %>
Run Code Online (Sandbox Code Playgroud)
这行是完美地打印到控制台的值:
<%= _.each(@place.get("hash"),(count, tag) -> console.log "#{tag} ") %>
Run Code Online (Sandbox Code Playgroud)
当我尝试使用打印命令并刷新时,谷歌浏览器会抛出一个打印菜单.我该如何解决这个问题
除了有用的下划线方法亩太短提到的,你也可以使用CoffeeScript中的原生for of的生态:
<% for tag of @place.get("hash"): %>
<%= tag %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
如果您需要在每个元素周围添加一些标记,这可能很有用.例如:
<ul>
<% for tag of @place.get("hash"): %>
<li><%= tag %></li>
<% end %>
</ul>
Run Code Online (Sandbox Code Playgroud)