Marionette 事件点击。如何获取点击项的属性?

Marionette events click. How to get attribute of clicked item?

如何使用 Marionette 的点击事件从 players.html 获取 value 属性?我基本上需要知道哪个玩家被点击了。这是我的代码:

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
    }
});

...

您可以在事件处理程序中检查 e.currentTarget

playerSelect: function(e) {
  var playerValue = e.currentTarget.getAttribute('value');
}

顺便说一句,player 不是已知的 HTML 标签,也不是 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 的有效名称。

如果这不是您想要的,可能需要使用标准 HTML5 tag