I'm experimenting with the leaderboards example and I would like to unset the selected_player
when you click outside a player name. I figured for this to work, I'd need to add a listener event to the body element and prevent it from triggering other elements that are inside it. Then I would set selected_player
to 0.
However I only seem to be able to add event maps to Templates?
Template.player.events({
'click': function () {
Session.set("selected_player", this._id);
}
});
Am I missing something? How can I listen to a 'click' event for the whole page?
I'm experimenting with the leaderboards example and I would like to unset the selected_player
when you click outside a player name. I figured for this to work, I'd need to add a listener event to the body element and prevent it from triggering other elements that are inside it. Then I would set selected_player
to 0.
However I only seem to be able to add event maps to Templates?
Template.player.events({
'click': function () {
Session.set("selected_player", this._id);
}
});
Am I missing something? How can I listen to a 'click' event for the whole page?
Share Improve this question edited May 22, 2020 at 6:58 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Nov 8, 2012 at 21:26 NickNick 12k8 gold badges45 silver badges47 bronze badges 1- 3 put the body inside a template and a event to the template – Pedro Luz Commented Nov 13, 2012 at 0:06
1 Answer
Reset to default 13There is no good way to bind events to the whole body. However, you can wrap all your code in one outer template that has events, as Narven suggests.
<body>
{{> outer}}
</body>
<template name="outer">
your stuff
</template>
and
Template.outer.events({
'click': function () {
do stuff
}
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743763084a4502993.html
评论列表(0条)