从接近onBeforeClose prevent木偶视图 [英] Prevent Marionette view from close onBeforeClose
问题描述
我是从做编辑通过表单模型,并轻松地浏览从变化远试图prevent用户。想想Gmail时,你已经开始撰写的邮件。
I'm trying to prevent the user from making an edit to a model via form and easily navigating away from that change. Think Gmail when you've started composing a message.
有人张贴在GitHub上描述了同样的情况的问题。
https://github.com/marionettejs/backbone.marionette/issues/186
Someone has posted an issue on GitHub that describes the same situation. https://github.com/marionettejs/backbone.marionette/issues/186
这个问题被关闭,因为人建议你尝试关闭视图前应检测的变化。
This issue was closed because people suggest you should detect changes before attempting to close a view.
但是这种方法的问题是有有几种方法的图可以关闭。后退按钮,点击一个新的导航项目,取消视图按钮。
But the problem with this approach is there there are several ways a view can be closed. Back button, clicking a new nav item, cancel button on the view.
既然已经存在,你会认为你可以从这里取消关闭的onBeforeCLose回调。这难道不是在所有可能的?
Since there is already an onBeforeCLose callback you would think you could cancel the close from here. Is this not at all possible?
推荐答案
你问的是内置在 onBeforeClose
方法现在什么。在那个票#186撰写时,基础设施不到位这一点。事情发生了变化,它突然变成了单行实现这一点,所以我所做的:)
What you're asking for is built in to the onBeforeClose
method now. At the time that ticket #186 was written, the infrastructure wasn't in place for this. Things changed, and it suddenly became a one-liner to implement this, so I did :)
<一个href=\"https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.view.md#view-onbeforeclose\" rel=\"nofollow\">https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.view.md#view-onbeforeclose
MyView = Marionette.View.extend({
onBeforeClose: function(){
// prevent the view from being closed
return false;
}
});
var v = new MyView();
v.close(); // view will remain open
这篇关于从接近onBeforeClose prevent木偶视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!