admin管理员组文章数量:1278854
using Backbone.js with Marionette.js (Go Derick Bailey!). Need to detect when a view is removed from the page. Specifically, I'm overwriting it with another view.
Is there an event I can detect of function I can overload to detect when this happens?
Thanks!
using Backbone.js with Marionette.js (Go Derick Bailey!). Need to detect when a view is removed from the page. Specifically, I'm overwriting it with another view.
Is there an event I can detect of function I can overload to detect when this happens?
Thanks!
Share Improve this question asked Jan 13, 2013 at 0:35 Chris DutrowChris Dutrow 50.4k67 gold badges195 silver badges262 bronze badges 1-
1
the bination of fencliff and Hurricanepkt's answers is what you want... use a region to manage the view being displayed within a DOM element, and listen for the "close" event, or use the
onClose
callback when needed. – Derick Bailey Commented Jan 13, 2013 at 4:35
2 Answers
Reset to default 11Marionette provides the View.onClose
method for this purpose:
Backbone.Marionette.ItemView.extend({
onClose: function(){
// custom cleanup or closing code, here
}
});
In vanilla Backbone you can override the View.remove
method:
Backbone.View.extend({
remove: function(){
// custom cleanup or closing code, here
// call the base class remove method
Backbone.View.prototype.remove.apply(this, arguments);
}
});
Neither of these methods will work if you are simply clobbering the view's DOM element. If that is your case, the solution is simple: Don't do that. Remove the previous view explicitly before rendering another view in its place.
The region show function is going to do most of what you are looking for
https://github./marionettejs/backbone.marionette/blob/master/docs/marionette.region.md#basic-use
And look at the on show event later in the page
本文标签: javascriptDetect when a view is removed from the page using Backbonejs or MarionettejsStack Overflow
版权声明:本文标题:javascript - Detect when a view is removed from the page using Backbone.js or Marionette.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741239286a2363649.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论