是否可以在 Meteor 事件地图中使用嵌套选择器? [英] Is it possible to use nested selectors in Meteor event maps?

查看:28
本文介绍了是否可以在 Meteor 事件地图中使用嵌套选择器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里,我想从 .header 元素中选择 .accept 元素.这可能吗?文档尚无定论,我尝试了一些变体但无济于事,有没有我没有的技巧知道吗?

'click .header .accept': function (event) { ... },

在 jQuery 中我可能会使用这个:$('.header .accept')

解决方案

假设您在其他地方没有冲突,您共享的内容将起作用.尝试使用下面的代码.仅当您根据需要单击第二个 div 时才会触发该事件.

模板:

{{>页}}<模板名称=页面"><div class="header">.header<div class="accept">.header .accept</div>

js:

if (Meteor.isClient) {模板.page.events({'点击 .header .accept':函数(事件){console.log('接受点击');}});}

Here, I would like to select the .accept element from within the .header element. Is this possible? The documentation is inconclusive and I have tried some variations to no avail, is there a trick I'm not aware of?

'click .header .accept': function (event) { ... },

In jQuery I might use this: $('.header .accept')

解决方案

What you shared will work assuming you don't have a conflict elsewhere. Try using the code below. The event fires only if you click the second div, as you want.

template:

<body>
    {{> page}}
</body>

<template name="page">
    <div class="header">.header 
        <div class="accept">.header .accept</div>
    </div>
</template>

js:

if (Meteor.isClient) {
    Template.page.events({
        'click .header .accept': function(event) {
            console.log('accept clicked');
        }
    });
}

这篇关于是否可以在 Meteor 事件地图中使用嵌套选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆