javascript - Meteor:从 JavaScript 内部调用/触发事件?

标签 javascript meteor

我有一个如下所示的事件:

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/

相关文章:

java - 在监控应用中使用 Meteor 框架

javascript - jQuery不同的div id显示/隐藏

javascript - session 变量默认为最后一组

javascript - 在函数结束前更改文档

javascript - meteor 在meteor.com上写入文件

javascript - MongoDB 聚合 - $project 中的动态字段路径

javascript - 图表不会绘制。返回字符串值而不是数字值 - Meteor - Chartjs

javascript - iframe 中的 window.location.href 在 FireFox 中不起作用

debugging - 如何调试 "Exception in defer callback: Error: failed to copy newResults into _published!"?

meteor - 如何防止 Meteor 的账户自动发布当前用户的电子邮件?