Ext组件设计思想

第一阶段:初始化 creation

包括初始配置设定、事件注册、预渲染处理等。

  • 1、应用组件的配置: // Ext.apply(this, config)

  • 2、注册事件: (click, mouseover等)

  • 3、在ComponentMgr注册组件实例: 生成唯一ID值,供Ext.Cmp()方法来获得该实例的引用。

  • 4、调用initComponent()方法:继承了Ext.Component基类的组件中,通常使用的时候会覆盖父类的initComponent()方法。可以使用this.callParent()来回调父类函数。

  • 5、加载插件和组件渲染:

第二阶段:组件呈现 rendering

创建页面dom元素

  • 1、触发beforerender事件:组件被render渲染前被调用的。用以提供处理函数或者阻止组件的继续渲染。

  • 2、调用onReader方法:组件一个比较重要的方法,在子类组件中可以根据需要重写覆盖。通过superclass.onRender 来调用父类的 onRender 方法。

  • 3、触发render事件:通知组件已经被成功的呈现了。

  • 、调用 afterRender :根据逻辑需要可以重新实现或覆盖该方法。可以通过调 superclass.afterRender.来调用父类的方法。

第三阶段:销毁

  • 1、触发事件 beforedestroy

  • 2、调用 beforeDestroy 方法

  • 3、移除事件监听者 :移除元素的事件监听列表,然后将元素从 DOM中移除。

  • 4、onDestroy 被调用

  • 5、组件实例从 ComponentMgr 中反注册 :不可以再通过 Ext.getCmp 获取到对象实例。

  • 6、触发destroy 事件

组件可以独立于元素,自己拥有事件代理,如果存在则移除它们。

    Ext.Component = function(config) {

        this.initialConfig = config;
        Ext.apply(this, config);

        this.addEvents();

        this.getId();
        Ext.ComponentMgr.register(this);
        Ext.Component.superclass.constructor.call(this);

        this.initComponent();

        if (this.plugins) {
            this.plugins = this.initPlugin(this.plugins);
        }

        this.render(this.renderTo);

        // render: function(container, position) {
        //     this.fireEvent('beforerender', this)

        //     this.onRender(this.container, position || null);
        //     this.fireEvent('render', this);

        //     this.afterRender(this.container);
        //     this.fireEvent('afterrender', this);
        //     return this;
        // },

        // destroy: function() {
        //     this.fireEvent('beforedestroy', this)

        //     this.beforeDestroy();
        //     this.ownerCt.remove(this, false);

        //     this.container.remove();

        //     this.onDestroy();
        //     Ext.ComponentMgr.unregister(this);

        //     this.fireEvent('destroy', this);
        //     this.isDestroyed = true;
        // }
    };

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值