【发布时间】:2014-06-25 05:35:59
【问题描述】:
我对 _.template(或 jQuery(或我对这两者的知识))有一个奇怪的问题。我使用 Underscore 渲染模板和 jQuery 将元素附加到 DOM(以及许多其他东西)。 像这样:
var $section = $(this.tmpl.section(data));
一切都很好,但是当我在模板 html 中添加 html 注释时,比如
<script id="section-template" type="text/template">
<!-- Section panel -->
<div class="panel section-panel panel-info section-<%= type %>" data-type="<%= type %>" data-layout="<%= layout %>">
<div class="panel-heading section-handle">
<h3 class="panel-title"><%= title %></h3>
</div>
<div class="panel-body"></div>
</div>
</script>
我收到一个对象数组。我可能在这里遗漏了一些基本的东西,但这是 jQuery 在输入这个 html 时应该工作的方式吗?我认为它应该忽略 cmets。
【问题讨论】:
-
尝试使用
-
在脚本中
//触发 cmets -
@ejay_francisco 你有关于非 JavaScript 脚本的参考吗?
-
<%-- Section panel --%>不起作用,//cmets 起作用,但那是下划线 cmets,它们没有显示在 html 代码中,我想在前面放一些漂亮的 cmets - 结束)但无论如何,感谢您的建议。可能不添加任何额外逻辑的唯一方法是将 cmets 包含在 div 中,但这并不是我想要的。 -
这与下划线无关,这只是 jQuery 对字符串中有多少标签感到困惑:jsfiddle.net/ambiguous/E8Caq 你为什么要在模板中添加评论?
标签: javascript jquery templates underscore.js