Created
July 31, 2013 22:42
-
-
Save andrewshatnyy/6126879 to your computer and use it in GitHub Desktop.
Basic Bootstrap Modal in backbone that will clean up after itself to avoid memory leaks. View triggered on button click => modalView = new BaseModalView();
modalView.show();
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(['underscore', 'backbone', ], function(_, Backbone) { | |
var BaseModalView = Backbone.View.extend({ | |
id: 'base-modal', | |
className: 'modal fade hide', | |
template: 'modals/BaseModal', | |
events: { | |
'hidden': 'teardown' | |
}, | |
initialize: function() { | |
_(this).bindAll(); | |
this.render(); | |
}, | |
show: function() { | |
this.$el.modal('show'); | |
}, | |
teardown: function() { | |
this.$el.data('modal', null); | |
this.remove(); | |
}, | |
render: function() { | |
this.getTemplate(this.template, this.renderView); | |
return this; | |
}, | |
renderView: function(template) { | |
this.$el.html(template()); | |
this.$el.modal({show:false}); // dont show modal on instantiation | |
} | |
}); | |
return BaseModalView; | |
}); |
ummm, this.getTemplate() is not defined. There appear to be several problems with this example. Prove me wrong or take it down.
same issue, getTemplate() is a marionette.view method, so you need to use marionette over backbone if you want to use this realisation.
@yairEO hey, sorry haven't seen these comments. But it's better late then never. I had no idea removeData()
existed then. Will try it on the next contract, thanks.
@eightyeight, @the1mills same see original thread https://stackoverflow.com/questions/16085852/rendering-bootstrap-modal-using-backbone/17982356. I didn't have my notifications turned on
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why don't you use
removeData()
instead of NULL-ing it?