javascript - 如何在生态模板中打印 _each 方法的结果

标签 javascript coffeescript underscore.js eco

我确定我做错的很简单,但似乎找不到解释。我的模板中有以下行,它没有向 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/

相关文章:

coffeescript - 错误 : connect EINVAL 0. 0.xx.xx :80 - Local (0. 0.0.0:0)

javascript - 使用 underscore.js 过滤数组

javascript - 为什么展开运算符将对象参数转换为一项数组?

javascript - 在 vue.js 中设置输入元素的焦点

javascript - 我不明白 JavaScript 中的设置日期方法是如何工作的

node.js - 使用node.js和coffeescript执行Ubuntu命令

arrays - 如何使用 CoffeeScript 对数组进行排序?

javascript - 更改对象数组中的数据类型

javascript - 现在使用 jQuery - Backbone.Js 调用页面方法

javascript - 如何在纯 JavaScript 的帮助下对表格进行排序和重新生成