我在流星遇到了一個非常奇怪的問題...流星模板數據對象阻止JavaScript事件發射?
我有一個函數呈現模板並將其追加到div,在添加的模板中有一個可以觸發偵聽器事件的按鈕。
奇怪的是,當我渲染沒有任何數據對象作爲參數的模板時,可以觸發點擊事件,但只要我將數據對象傳入模板,新添加的模板中的所有JavaScript都停止工作。 ..
理想情況下,我希望能夠將數據傳遞給模板並讓事件正確觸發,有人知道這裏發生了什麼嗎?非常感謝!
故障情形與數據傳遞到模板:
client.coffee
Template.detail.events {
'click .ol_self_help_btn': (event) ->
alert 'event fired' //This is never triggered
}
Template.room.events {
'click .ol_detail': (event) ->
element = $(event.currentTarget).closest('.ol_property')
element.append Meteor.render Template.detail @ //Passing in "this" data object to the template
}
detail.html
<Template name="detail">
<div class="row ol_detail_panel">
<button style='button' class='ol_self_help_btn'>Click Me</button> //The button that the event is attached to
</div>
</div>
</Template>
成功場景沒有數據對象傳:
client.coffee
Template.detail.events {
'click .ol_self_help_btn': (event) ->
alert 'event fired' //This is triggered when clicking on the button
}
Template.room.events {
'click .ol_detail': (event) ->
element = $(event.currentTarget).closest('.ol_property')
element.append Meteor.render Template.detail //NOT Passing in data to the template function
}
detail.html
<Template name="detail">
<div class="row ol_detail_panel">
<button style='button' class='ol_self_help_btn'>Click Me</button> //The button that the event is attached to
</div>
</div>
</Template>