简体   繁体   English

上下文更改事件不起作用流星

[英]Context change events won't work Meteor

So i've got a structure like this 所以我有一个这样的结构

<template name="example">

{{#each post}}
<div class="hello"></div>
{{/each}}

</template>

So now I am trying to check for click events on the hello div like so 所以现在我正在尝试像这样检查hello div上的点击事件

Template.example.events = {
  'click .hello' : function(event) {

     console.log("hey");

  }    
}

But this is not working. 但这是行不通的。 Console is not logging anything. 控制台未记录任何内容。

Does this have to do anything with the change of context in the html template? 这与html模板中的上下文更改有关系吗?

events is a function that you need to pass an event map to. events是您需要将事件映射传递到的功能。 Right now you are assigning an event map and overriding the actual events method. 现在,您正在分配事件映射并覆盖实际events方法。 Try this: 尝试这个:

Template.example.events({
  'click .hello' : function(event) {
     console.log("hey");
  }    
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM