Backbone.js 木偶。在区域关闭之前调用布局onBeforeClose?

Backbone.js 木偶。在区域关闭之前调用布局onBeforeClose?,backbone.js,marionette,Backbone.js,Marionette,我有一个木偶布局,它管理一组区域子视图,其中包含我想在用户离开页面之前保存的信息。我在布局中使用了onBeforeClose()。此外,在onBeforeClose()中返回false似乎也不会防止子视图的破坏。关于是否有替代方法,或者是否应该更早调用木偶的onBeforeClose()有什么想法吗 其他人建议在关闭之前检测更改,但正如本文()所述,它并不能捕获所有关闭案例。当我需要更改默认行为时,我通常会编写自己的close方法。如果要重复使用,我将创建一个mixin。比如: close: f

我有一个木偶布局,它管理一组区域子视图,其中包含我想在用户离开页面之前保存的信息。我在布局中使用了
onBeforeClose()。此外,在
onBeforeClose()中返回
false
似乎也不会防止子视图的破坏。关于是否有替代方法,或者是否应该更早调用木偶的
onBeforeClose()
有什么想法吗


其他人建议在关闭之前检测更改,但正如本文()所述,它并不能捕获所有关闭案例。

当我需要更改默认行为时,我通常会编写自己的
close
方法。如果要重复使用,我将创建一个mixin。比如:

close: function() {
    if (this.isClosed){ return; }
    // the following if statement is the only difference between
    // Marionette.Layout.close and my view's version.
    // Everything in the if is original
    if ( myCondition ) {
        this.regionManager.close();
        var args = Array.prototype.slice.apply(arguments);
        Marionette.ItemView.prototype.close.apply(this, args);
    }
}

这不一定是你想要的,但它是一种选择
onBeforeClose
Marionette.View.close
调用,后者又从
ItemView.close
调用。这是我找到的唯一获得我想要的控制权的方法。

Hm,我想覆盖木偶将是一种选择。。。不太理想。是否有理由不在区域关闭之前调用布局的onBeforeClose?这将是允许onBeforeClose返回false以停止关闭过程的唯一方法。