Getting session problem


#1

I’m learning making an app from a tutorial:
http://meteortips.com/first-meteor-tutorial/databases-part-2/

But there is some thing wrong with it:
It should after clicking a button logging the selected player _id in the console but when I click a li
element it logs the selected player _id.

Do you thing it’s a Incompatibility from previous and new version of meteor or there is something wrong with my code?

javascript:

 Template.leaderboard.events({
            'click.player': function () {
    
                var playerId = this._id;
                Session.set('selectedPlayer', playerId);
    
    
            },
    
    
            'click.increment': function () {
                var selectedPlayer = Session.get('selectedPlayer');
                //PlayersList.update(selectedPlayer, { score: 5 });
                console.log(selectedPlayer);
            }
    
    
        });

html:

<head>
    <title>Leaderboard</title>
</head>

<body>
    <h1>Leaderboard</h1>
    {{>leaderboard}}
</body>

<template name="leaderboard">
    <ul>
        {{#each player}}
        <li class="player {{selectedClass}}">{{name}}:{{score}}</li>
        {{/each}}
        <li><button class="increment">Give 5 Points</button></li>

    </ul>
</template>

thanks
Saeed


#2

You need a space between the event type and the selector in your event map:

ie 'click.player' should be 'click .player' and
'click.increment' should be 'click .increment'

Template.leaderboard.events({
  'click .player': function() {
    ...
  },
  'click .increment': function() {
    ...
  }
});

#3

Thanks a lot for your answer. Now it works well.
I was disappointed that someone would answer me.:wink: