我确定我做错的很简单,但似乎找不到解释。我的模板中有以下行,它没有向 html 输出打印任何值:
<%= _.each(@place.get("hash"),(count, tag) -> "#{tag} ") %>
这一行完美地将值打印到控制台:
<%= _.each(@place.get("hash"),(count, tag) -> console.log "#{tag} ") %>
当我尝试使用打印命令并刷新时,谷歌浏览器会弹出一个打印菜单。我该如何解决这个问题
最佳答案
除了有用的Underscore方法外mu太短了mentioned , 你也可以在 Eco 中使用 CoffeeScript 的原生 for of
:
<% for tag of @place.get("hash"): %>
<%= tag %>
<% end %>
如果您需要在每个元素周围添加一些标记,这会很有用。例如:
<ul>
<% for tag of @place.get("hash"): %>
<li><%= tag %></li>
<% end %>
</ul>
关于javascript - 如何在生态模板中打印 _each 方法的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10519502/