javascript - How to listen for click events on the whole page in meteor? - Stack Overflow

I'm experimenting with the leaderboards example and I would like to unset the selected_player when

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
Add a ment  | 

1 Answer 1

Reset to default 13

There 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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信