4

我已经包含了这张票中描述的资产,并且下划线变量除了在标签内时有效。我无法获取变量以在动态标签内呈现以使用 Backbone 事件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>

使用(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 
4

3 回答 3

10

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

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

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

于 2013-01-15T05:11:30.320 回答
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>

或者你可以看看使用玉模板而不是下划线模板。

于 2012-11-30T00:29:04.937 回答
2

Now we can use script. to insert a block of plain text as described here: 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>
于 2014-09-12T08:30:52.650 回答