4

このチケットに記載されているアセットを含めました。アンダースコア変数は、タグ内の場合を除いて機能します。バックボーンイベントを処理する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

翡翠でアンダースコアテンプレートを使用する場合は、次のようにテンプレートを変更する必要があります。

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

これで、http: //jade-lang.com/reference/plain-text/script.で説明されているように、プレーンテキストのブロックを挿入するために使用できます。

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 に答える