我有一个如下所示的事件:
Template.foo.events({
'bar': function() {
console.log("Hello!");
}
});
如何使用 JS 从客户端调用/触发它?类似于:
qwe = new Event(foo);
qwe.dispatchEvent();?
最佳答案
查看 Meteor 文档中的事件:http://docs.meteor.com/#/basic/Template-events
"The first part of the key (before the first space) is the name of the event being captured. Pretty much any DOM event is supported. Some common ones are: click, mousedown, mouseup, mouseenter, mouseleave, keydown, keyup, keypress, focus, blur, and change."
因此,在您的示例中,“bar”应该替换为“click”之类的内容。当您的模板被点击时,这甚至会被触发。
关于javascript - Meteor:从 JavaScript 内部调用/触发事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29876429/