当前位置: 代码迷 >> JavaScript >> Extjs xtype 深入懂得
  详细解决方案

Extjs xtype 深入懂得

热度:344   发布时间:2012-11-23 22:54:33.0
Extjs xtype 深入了解

做Extjs有一段时间了,遇到了各种问题,现在我对xtype 做一下总结和基本的说明

?

xtype 就是Extjs 用于创建对象的一种形式

?

就比如xtype:'button' 就会创建Button对象似的

?

但这些xtype是谁来管理的,在看了源代码和大量实践后,发现

?

?

'Ext.ComponentManager‘

?

是管理xtype和component对象的

?

在这个里面我们可以很轻松的发现,extjs是会先把messagebox相应的component都加载进来,在进行你定义的xtype处理的

?

xtype到底有什么好处那?

?

生成对象的代码如下:

?

create: function(component, defaultType){
        if (component instanceof Ext.AbstractComponent) {
            return component;
        }
        else if (Ext.isString(component)) {
            return Ext.createByAlias('widget.' + component);
        }
        else {
            var type = component.xtype || defaultType,
                config = component;
            
            return Ext.createByAlias('widget.' + type, config);
        }
    },
?

1.内存节约

2.加快browser运行速度

?

其实可以这样说,这种方式就是延迟实例化

?

很明了吧

?

extjs的工作基本流程是

?

1.实例化

2.渲染

3.显示

?

上面xtype延迟实例化

那么可以想象,如果你用Ext.create或者new对象的形式,创建extjs component 那么

xtype的属性是在上面定义的组件显示的时候才会被创建然后渲染,显示。

?

这就是很多人不明白的extjs 组件创建流程

?

?

  相关解决方案