How to Delete controller ExtJS? extjs多个app时,删除其他app的controller

来源:互联网 发布:网络销售门票协议书 编辑:程序博客网 时间:2024/06/06 13:02

ExtJs currently does not support removal of controllers out of the box. To cleanup a controller, do the following:

  • Extend Ext.app.EventBus with a method uncontrol that unregisters all event listeners that this controller registered on the EventBus. Check out the source of Ext.app.EventBus#control to derive an implementation. Or use this one.
  • Extend Ext.app.Application with a method removeController that removes a given controller instance from the controllers collection. It's a Ext.util.MixedCollection, check out the source for Ext.app.Application#getController. Then clean up all registered listeners for that controller using uncontrol.
  • Implement a destroy method either on your specific controller and/or extend Ext.app.Controller. You should at least call clearManagedListeners() and possibly destroy other objects created by this controller like views or stores, if that suits your application architecture and controller life-cycle.



 source:

Ext.override(Ext.app.EventBus,{uncontrol:function(controllerArray){var me=this,bus=me.bus,deleteThis,idx;Ext.iterate(bus,function(ev,controllers){Ext.iterate(controllers,function(query,controller){deleteThis=false;Ext.iterate(controller,function(controlName){idx=controllerArray.indexOf(controlName);if(idx>=0){deleteThis=true;}})if(deleteThis){delete controllers[query];}})})}})Ext.override(Ext.app.Application,{removeController:function(controllerArray){var me = this;        me.eventbus.uncontrol(controllerArray);}})Ext.override(Ext.app.Controller,{destroy:function(){var me=this;this.clearManagedListeners();}})


0 0
原创粉丝点击