I do not understand what happens with the Spacebars {{#each}}
template tag.
For example I have a simple event code:
'click #player': function(){
var playerId = this._id;
Session.set('selectedPlayer', playerId);
Session.set('selectedPlayerName', this.name);
}
And this corresponding code in the template:
{{#each player}}
<a href="#" id="player" class="{{selectedClass}}"></a>
{{/each}}
And finally this helper:
'selectedClass': function(){
return this._id
}
How do the event handler and the helper function knows which of the list items is being referred to?
The HTML produced by this is invalid, due to multiple elements having the same
id
-attribute. The event-handler is simple to explain. the keys inside anevent-map
are split intoevent-type
and optionallyevent-target
. Theevent-target
is passed to jQuery, which tolerates the invalid usage ofid
s. So jQuery adds event-listeners to all elements with the idplayer
.Matt K explained the rest pretty well.