在父模板中监听子模板的事件

时间:2016-03-04 10:52:29

标签: javascript dom meteor

我注意到不同浏览器中Meteor事件监听器的不一致。我可以在Chrome上监听儿童模板中触发的事件,但这不适用于Firefox和Safari(可能还有IE,呃)。

这是最小的复制代码:

Template.thisIsTheParent.events({
    'click .a-class-that-lives-in-children': function(e, t) {
        // Do something
    }
});

Template.thisIsAChildBetweenOthers.events({
    // On FF/Safari, I must put an event listener here on each children,
    // that leads to massive code duplication.
    'click .a-class-that-lives-in-children': function(e, t) {
        // Do something that the parent should do :/
    }
});

空格键(使用yield模板由铁路由器处理):

<template name="thisIsTheParent">
    <div>
        {{ > yield }}
    </div>
</template>

<template name="thisIsAChildBetweenOthers">
    <a class="a-class-that-lives-in-children">I want to handle the click on that in the parent</a>
</template>

在Chrome上,会调用第一个事件侦听器,但不会在其他浏览器中调用。这是预期的行为吗?

0 个答案:

没有答案