【发布时间】:2015-01-26 20:10:56
【问题描述】:
我在 js 中有以下行:
terminalsListHtml += this.compiled(_.extend(this.terminals[i], {clazz: 'all'}, obj));
我调试以下代码:
尝试评估_.extend(this.terminals[i], {clazz: 'all'}, obj):
看起来不错
但尝试评估
this.compiled(_.extend(this.terminals[i], {clazz: 'all'}, obj));
这对我来说不是预期的结果。
请帮助解决所描述的问题。
附言
window.MARC = {
addTerminalPage: {
....
compiled: _.template($('#terminal-template').text()),
<script type="text/template" id="terminal-template">
<li data-terminal-id="{{ id }}" class="{{ clazz2 }}">
<label>
<input type="checkbox" name="terminal" class="{{ clazz }}" data-terminal-id="{{ id }}" />
<a href="#" title="" class="image"><img
src="<c:url value='/resources/images/img1.png'/>"
alt=""/></a>
<h3>{{ name }}
<small>{{ place }}</small>
</h3>
<p>{{ description }}</p>
<p class="count">Проходимость: <span>{{ count }}</span> чел./час</p>
<p class="count">Стоимость: <span>{{ amount }}</span> руб./час</p>
</label>
</li>
</script>
附言
_.templateSettings = {
interpolate: /\{\{(.+?)\}\}/gim,
evaluate: /\{\{(.+?)\}\}/gim,
escape: /\{\{\-(.+?)\}\}/gim
};
【问题讨论】:
-
默认下划线模板使用 ERB 语法,例如
<span><%= foobar %></span>。您是否指定要使用下划线来使用 mustache.js 样式<span>{{ foobar }}</span>模板?有关如何启用此功能的信息,请参阅template section of the underscore.js docs。 -
您更新
_.templateSettings以使用Handlebars 语法了吗? -
@mu 太短了,您是否放弃了这个 _.templateSettings = { 插值:/\{\{(.+?)\}\}/gim,评估:/\{\ {(.+?)\}\}/gim,转义:/\{\{\-(.+?)\}\}/gim }; ?
-
@mu 太短了,你的评论对我有帮助。
标签: javascript templates underscore.js