Rendering a closed Marionette view

backbone.js, marionette

Solution

If I understand your question right, there are multiple open github issues about this.

For example:

https://github.com/marionettejs/backbone.marionette/pull/654 https://github.com/marionettejs/backbone.marionette/issues/622

Last time I checked, Derick (the creator of Marionette) didn't feel like reusing closed views should be something regions should do.

So you could

- simply create a new view and show that one

- manually call delegateEvents - but there was an issue with multiple event bindings that I can't remember right now, so be careful about that one (not at work right now, so can't take a peek at the code, sorry)

- write your own region manager

- or wait and see if Derick will merge one of the pull requests

Problem

Shouldn't a closed Marionette view re-delegate the defined events (events, modelEvents, CollectionEvents) when rendering again? It seems as if I have to manually call delegateEvents after closing and re-rendering a view. Otherwise the view won't work as expected. http://jsfiddle.net/4DCeY/ ``` var app = new Marionette.Application(); app.addRegions({ main: '.main' }); var MyView = Marionette.ItemView.extend({ template: _.template('Hi, I\'m a view! Foo is: <%= foo %>'), modelEvents: { 'change': 'onChange' }, onChange: function() { alert('change!'); } }); var Model = Backbone.Model.extend({}); app.addInitializer(function() { var m = new Model({foo: 'bar'}); var myView = new MyView({ model: m }); app.main.show(myView); myView.close(); app.main.show(myView); m.set({foo: 'baz'}); }); $(document).ready(function(){ app.start(); }); ```

Original source