【发布时间】:2013-07-09 12:14:38
【问题描述】:
我希望我的 Marionette 视图以动画方式关闭并等待动画完成,然后再将它们从 DOM 中删除。
(我们将非常感谢您的见解)
我用以下方式重写了 Marionette.View 关闭方法:
close: function(){
if (this.isClosed) { return; }
// allow the close to be stopped by returning `false`
// from the `onBeforeClose` method
var beforeCloseReturnValue = this.triggerMethod("before:close");
if (beforeCloseReturnValue === false){
return;
}
if (IsObjectNullOrUndefined(beforeCloseReturnValue))
{
this.closeTheView();
return;
}
if (beforeCloseReturnValue.promise)
{
var _this = this;
$.when(beforeCloseReturnValue).done(function(){
console.log("view close done!");
_this.closeTheView();
});
}
},
closeTheView: function(){
// mark as closed before doing the actual close, to
// prevent infinite loops within "close" event handlers
// that are trying to close other views
this.isClosed = true;
this.triggerMethod("close");
// unbind UI elements
this.unbindUIElements();
// remove the view from the DOM
this.remove();
}
视图实例包含以下 onBeforeClose 方法的实现:
onBeforeClose: function(){
_this = this;
return $.Deferred(function(){
_this.$el.fadeOut(2000, dfd.resolve);
}).promise();
}
到目前为止效果很好。
想听听您是否对此有任何想法。
谢谢。
【问题讨论】:
-
你得到这个问题的答案了吗?
标签: backbone.js marionette backbone-views