Marionette.Layout onBeforeClose在地区关闭前呼叫?

时间:2013-07-08 19:02:52

标签: backbone.js marionette

我有一个Marionette.Layout管理一堆区域子视图,其中包含我想在用户导航离开页面之前保存的信息。我在布局中使用onBeforeClose(),但在布局之前,区域似乎已关闭并被删除。此外,在false中返回onBeforeClose()似乎也不能阻止子视图的破坏。有关是否有替代方法或是否应该提前召唤木偶的onBeforeClose()的任何想法?

其他人建议在收盘前检测更改,但如此处所述(Prevent Marionette view from close onBeforeClose),它不会捕获所有关闭案例。

1 个答案:

答案 0 :(得分:0)

当我需要更改默认行为时,我通常最终会编写自己的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调用{{1}}。这是我发现获得我正在寻找的控件的唯一方法。