繁体   English   中英

在Jade中渲染下划线变量

[英]Rendering Underscore variables in Jade

我已经包含了此票证中描述的资产,并且除了内部标签之外,Underscore变量也起作用。 我无法在动态标签内部获取变量data-id=someid用于使用Backbone事件进行onClick

在标准HTML中:

<script type="text/template" id="template-action1-thing">
<tr>
   <td class="action-td" style="width: 10%;">
      <button id="do-remove" data-id="<%= obj.id %>">X</button>             
   </td>
</tr>
</script>

使用(Scalate)Jade,它不起作用:

script(id='template-action1-thing' type='text/template')
  p <%= obj.id %> Will render
  tr
    td.action-td(style='width: 10%;')
      button(id='do-remove' data-id='<%= obj.id %>') 
        | X

如果我做这个实际HTML与变量呈现正常,但不正确:

tr td(style='width: 10%;') button(id='do-remove_thing' data-id='myid') X

使用以下模板:

script(id='template-action1-thing' type='text/template')
  |   td.action-td(style='width: 10%;')
  |     button(id='do-remove_thing' data-id='<%= obj.id %>') X 

我知道这个问题已经得到解答,但在寻找更有说服力的解决方案时,我发现这也有效:

script(type='text/html', id='tpl-name')
  h3!='<%= foo %>'
  p!='<%= bar %>'

这允许您继续使用Jade语法。

如果要在jade中使用下划线模板,则需要更改为模板,如下所示:

script(id='template-action1-thing' type='text/template')
  | <tr>
  |   <td class="action-td" style="width: 10%;">
  |     <button id="do-remove" data-id="<%= obj.id %>">X</button>             
  |   </td>
  | </tr>

或者您可以使用jade模板而不是下划线模板。

现在我们可以使用script. 插入一个纯文本块,如下所述: http//jade-lang.com/reference/plain-text/

script(id='template-action1-thing' type='text/template').
    <tr>
       <td class="action-td" style="width: 10%;">
          <button id="do-remove" data-id="<%= obj.id %>">X</button>             
       </td>
    </tr>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM