在Jade中渲染下划线变量

4 javascript backbone.js underscore.js scalate pug

我已经包含了此票证中描述的资产,并且除了内部标签之外,Underscore变量也起作用.我不能让变量动态标签内呈现data-id=someid做事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>
Run Code Online (Sandbox Code Playgroud)

使用(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
Run Code Online (Sandbox Code Playgroud)

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

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

使用以下模板:

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

小智 10

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

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

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


phi*_*pvr 3

如果你想在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>
Run Code Online (Sandbox Code Playgroud)

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