javascriptbackbone.jsmarionettebackbone-viewsbackbone-events

Marionette.ItemView render event


It's hard to me to explain what I'm looking for, so I will start with code.

I have Marionette view like this:

Marionette.ItemView.extend({
    model: new Models.Cards(),
    template: 'poker/cards',
    events: {
        'click player': 'playerClicked'
    },
    playerClicked: function( e ) {
        // THIS WORKS!
    }
}

How can I do something like this:

    events: {
        'click player': 'playerClicked',
        'render player': 'playerRendered'
    },

so that playerRendered be called when <player> is rendered?


Solution

  • If you want to run some code when the ItemView itself is rendered, use onRender:

    Marionette.ItemView.extend({
      // ...
      onRender: function() {
        console.log("Rendered the ItemView!")
      }
      //...
    })
    

    Marionette doesn't have built-in events for parts of an ItemView being rendered.