【发布时间】:2012-04-24 01:41:31
【问题描述】:
更新 Jade v0.24.0 使用!= 属性语法修复了这个问题。 option(value!='<%= id %>')
我正在尝试使用jade 构建<option>,其中选项的值是UnderscoreJS 模板标记:<%= id %> 但我无法让它工作,因为jade 正在将我的标记文本转换为@987654325 @。
这是我的 Jade 标记:
script(id="my-template", type="text/template")
select(id="type")
<% _.each(deviceTypes, function(type){ %>
option(value='<%= type.id %>') <%= type.name %>
<% }) %>
我希望它能生成这个 html:
<script id="my-template" type="text/template">
<select id='type'>
<% _.each(deviceTypes, function(type){ %>
<option value="<%= type.id %>"> <%= type.name %> </option>
<% }) %>
</select>
</script>
但我得到的是这样的:
<script id="my-template" type="text/template">
<select id='type'>
<% _.each(deviceTypes, function(type){ %>
<option value="<%= type.id %>"> <%= type.name %> </option>
<% }) %>
</select>
</script>
请注意输出的<option> 行中的非常细微的差别...该选项的value 属性已被HTML 编码。
如何防止 Jade 对这个值进行 HTML 编码?我需要它来产生文字值,就像它处理选项的文本一样。
【问题讨论】:
-
我最近在使用下划线设置属性值时遇到了同样的问题,并找到了解决方法。不是超级漂亮,但比使用原始 HTML 更好。
标签: templates underscore.js pug html-encode string-literals