[英]How to trigger EventMap event for template from another template's event in Meteor.js?
我偶然發現了Meteor.js中一個非常時髦的要求—我有2個按鈕(“作為子項提交”和“作為同級項提交”)以及對按下按鍵有反應的文本輸入。 按鈕可以單獨工作,但是我想從輸入的keydown事件中觸發使用Template.my_template.events(...)進行的“ click”事件。
我設法使用EventMap和render()回調的以下構造(咖啡腳本)編寫所有腳本:
Template.my_template.events =
'keydown input': () -> reactToPressedKey();
Template.my_template.rendered = () ->
$('click .submit_child').bind 'click', () -> doStuff();
$('click .submit_sibling').bind 'click', () -> doStuff();
它的工作方式符合我的預期,但是我想知道是否還有更好的解決方案,例如僅使用EventMap(Template.my_template.events)?
只需將事件放在另一個模板中即可。
Template.other_template.events
'click .submit_child': doStuff
'click .submit_sibling': doStuff
Template.my_template.events
'keydown input': reactToPressedKey
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.