How can I get value
attribute from players.html
using Marionette's click event? I basically need to know which player was clicked. Here is my code:
players.html
{#myplayers}
<player class="standard" value="{player}" style="{style}"></player>
{/myplayers}
players.js
...
return Marionette.ItemView.extend({
model: new Models.Players(),
template: 'tmp/players',
events: {
'click player': 'playerSelect'
},
initialize: function() {
},
playerSelect: function(e) {
console.log('click test');
// I need here value (attribute), of player that was clicked
}
});
...
You can inspect e.currentTarget
in your event handler:
playerSelect: function(e) {
var playerValue = e.currentTarget.getAttribute('value');
}
As an aside, player
is not a known HTML tag or a valid name for a custom element. The HTML spec caters for unrecognised tags so your template will still be rendered, but it will be treated as an unknown element.
If that isn't what you intended may want to use a standard HTML5 tag.