/** * Created by jwj on 2015/4/13. * 增强Ext.panel.Panel(window,panel,form等界面组件)的beforeClose事件,以实现异步拦截 */ Ext.define('Ext.ux.overrides.panel.BeforeClose4async', { override: 'Ext.panel.Panel', /** * @event beforeclose * 以实现异步拦截事件(beforeclose) * @param this {Ext.panel.Panel} * @param handlers {obj} * @example * listeners: { * beforeClose: function (sender, handlers) { * handlers.wait = true; * //注意这里只是做了个弹出窗口示例,ajax异步拦截关闭事件道理类似 * Ext.MessageBox.confirm('提示:', '您确认要关闭此窗口吗?', function (btn) { * if (btn === 'yes') { * handlers.process(); * } else { * handlers.cancel(); * } * }); * } *} */ close: function () { /*if (this.fireEvent('beforeclose', this) !== false) { this.doClose(); }*/ var me = this, handled = false, handlers = { wait: false, process: function () { me.doClose(); handled = true; }, cancel: function () { handled = true; } }, performOperation = me.fireEvent('beforeclose', me, handlers); if (handlers.wait) { return; } if (performOperation !== false) { if (!handled) { handlers.process(); } } return performOperation; } }); 备注:在Extjs5.1下测试通过,自定义异步拦截事件都可参照此例进行实现。