我希望我的 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();
}
到目前为止工作得很好。
想听听您是否对此有任何想法。
谢谢。