0
여기에 문제가있어서 버그인지 내 어리 석음인지 잘 모르겠습니다. 이 같은 버튼 A와 B 버튼이 click
이벤트에 바인딩 (widget = $.tmpl(...)
로)이 템플릿을 렌더링 후중첩 템플릿에서 바운드 이벤트 손실 (?)
<!-- TEMPLATE A -->
<div class="mplc-widget">
<div class="mplc-widget-available">
<div class="mplc-widget-header">Available options</div>
<div class="mplc-widget-middle"><input></input></div>
<div class="mplc-widget-choices">
<table>
{{each(i, choice) choices}}
<tr name="${choice[0]}">
<td>${choice[1]}</td>
</tr>
{{/each}}
</table>
</div>
</div>
<div class="mplc-widget-selector">
<div><button>A</button></div>
<div><button>B</button></div>
</div>
<div class="mplc-widget-chosen">
<div class="mplc-widget-header">Selected options</div>
<div class="mplc-widget-choices">
<table>
</table>
</div>
</div>
</div>
:
나는이 템플릿 기반의 위젯을 구축했습니다
$('button', widget).bind('click', function(){alert('Hello world!');})
widget
이 반환됩니다. 이전 템플릿을 렌더링하고 이벤트를 결합하는 기능은, 다른 템플릿에서 호출되는 :이 템플릿 {{tmpl field.create()}}
에서
<!-- TEMPLATE B -->
<div class='form'>
<table>
{{each(i, field) fields}}
<tr>
{{if field.fieldname}}
<p>
<td {{if field.required}} class='field-required'{{/if}}>
${field.label}:</td> <td>{{tmpl field.create()}}
{{if field.help_text}}<br/><span class='help_text'>${field.help_text}</span>{{/if}}
</td>
</p>
</tr>
{{/if}}
{{/each}}
</table>
</div>
는 렌더링하고 template A
를 반환하는 기능을 나타냅니다. DOM에 삽입 할 때 모든 요소가 잘 표시되지만 바인드 함수 (create
으로 설정)가 손실됩니다!
이것이 올바른 동작입니까 아니면 완전히 잘못된 것입니까?