Chr*_*row 2 javascript backbone.js marionette
使用Backbone.js和Marionette.js(Go Derick Bailey!).需要检测何时从页面中删除视图.具体来说,我用另一种观点覆盖它.
是否有一个事件,我可以检测到功能,我可以重载,以检测何时发生这种情况?
谢谢!
jev*_*lio 11
Marionette View.onClose为此提供了方法:
Backbone.Marionette.ItemView.extend({
onClose: function(){
// custom cleanup or closing code, here
}
});
Run Code Online (Sandbox Code Playgroud)
在vanilla Backbone中,您可以覆盖该View.remove方法:
Backbone.View.extend({
remove: function(){
// custom cleanup or closing code, here
// call the base class remove method
Backbone.View.prototype.remove.apply(this, arguments);
}
});
Run Code Online (Sandbox Code Playgroud)
如果您只是破坏视图的DOM元素,这些方法都不会起作用.如果是这种情况,解决方案很简单:不要这样做.在呈现其位置的另一个视图之前,显式删除先前的视图.