Ext.util.Renderable

Hierarchy

Ext.Base
Ext.util.Renderable

Requires

Mixed into

Files

NOTE This is a private utility class for internal use by the framework. Don't rely on its existence.

给定一个组件的层次结构:

 {
     xtype: 'panel',
     id: 'ContainerA',
     layout: 'hbox',
     renderTo: Ext.getBody(),
     items: [
         {
             id: 'ContainerB',
             xtype: 'container',
             items: [
                 { id: 'ComponentA' }
             ]
         }
     ]
 }

它的渲染过程大致如下:

  • ContainerA的initComponent调用#render,传递renderTo属性 作为容器的参数。
  • render调用getRenderTree方法获取一个完整的Ext.DomHelper规格。
  • getRenderTree触发"beforerender"事件并调用#beforeRender 方法。通过调用#getElConfig获取结果。
  • getElConfig方法使用renderTpl和它的渲染数据

    作为autoEl所描述元素的内容。

  • getRenderTree的结果被传给Ext.DomHelper.append
  • renderTpl包含函数调用渲染像停靠项、容器项和 原始标记(比如html或者tpl配置属性)等元素。这些函数调用调用的是 使用#setupRenderTpl添加到Ext.XTemplate实例中的方法。
  • setupRenderTpl方法添加像renderItemsrenderContent等方法到那个模板。

    它们指向"doRenderItems"和"doRenderContent"等等。

  • setupRenderTpl调用遍历所有的组件和它们的Ext.layout.Layout

    对象。

  • 当一个容器渲染之后, 它也有一个renderTpl。它是在 组件的renderTpl内调用renderContainer方法时处理的。这个调用进入 Ext.layout.container.Container#doRenderContainer。这个方法为容器中的所有组件 重复这个过程。
  • 在最顶层的组件的标签产生并放入DOM之后,接下来的一步是 建立元素到组建的链接并完成调用组件的 onRenderafterRender方法,触发对应的事件。
  • 第一步是调用#finishRender。这个方法沿着组件的层级关系 往下调用onRender并触发render事件。这些调用执行是自顶向下的, 从前一个调用到 当前调用(事件)的时间。
  • 在传递的过程中, 组件的el被设置。同样,renderSelectorschildEls被应用以捕获对组件元素的引用。
  • 也在Ext.layout.container.Container布局上执行这些调用 以捕获它的元素。两个类都使用Ext.util.ElementContainer 来处理childEls的处理过程。
  • 这一完成, 通过调用#finishAfterRender完成类似的传递。 这个调用也沿着组件的层级体系往下, 但是这次调用是自底向上到afterRender
Defined By

Properties

扩展事件

Defaults to: []

本身 获取当前类的引用,此对象被实例化。不同于 statics, this.self是依赖范围,它意味着要使用动态继承。 ...

本身

获取当前类的引用,此对象被实例化。不同于 statics, this.self是依赖范围,它意味着要使用动态继承。 参见 statics 详细对比

Ext.define('My.Cat', {
    statics: {
        speciesName: 'Cat' // My.Cat.speciesName = 'Cat'
    },

    constructor: function() {
        alert(this.self.speciesName); // 依赖 'this'
    },

    clone: function() {
        return new this.self();
    }
});


Ext.define('My.SnowLeopard', {
    extend: 'My.Cat',
    statics: {
        speciesName: 'Snow Leopard'         // My.SnowLeopard.speciesName = 'Snow Leopard'
    }
});

var cat = new My.Cat();                     // alerts 'Cat' 猫
var snowLeopard = new My.SnowLeopard();     // alerts 'Snow Leopard' 雪豹

var clone = snowLeopard.clone();
alert(Ext.getClassName(clone));             // alerts 'My.SnowLeopard'

Methods

Defined By

Instance Methods

( Object config )private

添加配置

Parameters

Parameters

( Object name, Object member )private

Parameters

( Object xtype )private

添加 Xtype

Parameters

Ext.util.Renderable
( )protectedtemplate
允许完成渲染之后添加行为。在这个阶段,组件的元素 根据配置已经有了样式, 已经添加了任意CSS类名, 具有配置的可见性和启用状态。 ...

允许完成渲染之后添加行为。在这个阶段,组件的元素 根据配置已经有了样式, 已经添加了任意CSS类名, 具有配置的可见性和启用状态。

This is a template method. a hook into the functionality of this class. Feel free to override it in child classes.

Ext.util.Renderable
( )private

Sets references to elements inside the component. This applies renderSelectors as well as childEls.

( Array/Arguments ) : Objectdeprecatedprotected
调用原来的方法,这是以前的override重写 Ext.define('My.Cat', { constructor: function() { alert("I'm a cat!"); } }); ...

调用原来的方法,这是以前的override重写

Ext.define('My.Cat', {
    constructor: function() {
        alert("I'm a cat!");
    }
});

My.Cat.override({
    constructor: function() {
        alert("I'm going to be a cat!");

        this.callOverridden();

        alert("Meeeeoooowwww");
    }
});

var kitty = new My.Cat(); // alerts "I'm going to be a cat!"
                          // alerts "I'm a cat!"
                          // alerts "Meeeeoooowwww"

This method has been deprecated since 4.1

版本 使用 callParent 代替.

Parameters

  • : Array/Arguments

    参数的参数,数组或'参数'对象 来自当前方法,例如: this.callOverridden(arguments)

Returns

  • Object

    返回调用重写方法的结果。

( Array/Arguments args ) : Objectprotected

所谓的"parent"方法是指当前的方法。 这是以前的方法派生或重写(参见 Ext.define)。

 Ext.define('My.Base', {
     constructor: function (x) {
         this.x = x;
     },

     statics: {
         method: function (x) {
             return x;
         }
     }
 });

 Ext.define('My.Derived', {
     extend: 'My.Base',

     constructor: function () {
         this.callParent([21]);
     }
 });

 var obj = new My.Derived();

 alert(obj.x);  // alerts 21

这可以用来重写如下:

 Ext.define('My.DerivedOverride', {
     override: 'My.Derived',

     constructor: function (x) {
         this.callParent([x*2]); // 调用原来的My.Derived构造
     }
 });

 var obj = new My.Derived();

 alert(obj.x);  // 现在提示 42

This also works with static methods.

 Ext.define('My.Derived2', {
     extend: 'My.Base',

     statics: {
         method: function (x) {
             return this.callParent([x*2]); // 调用 My.Base.method
         }
     }
 });

 alert(My.Base.method(10);     // alerts 10
 alert(My.Derived2.method(10); // alerts 20

然后,它也可以重写静态方法。

 Ext.define('My.Derived2Override', {
     override: 'My.Derived2',

     statics: {
         method: function (x) {
             return this.callParent([x*2]); // 调用 My.Derived2.method
         }
     }
 });

 alert(My.Derived2.method(10); // 现在提示 40

Parameters

  • args : Array/Arguments

    这个参数, 通过当前方法得到数组或者 arguments 对象, 例如: this.callParent(arguments)

Returns

  • Object

    返回调用父类的方法的结果。

Ext.util.Renderable
( Object out, Object values )private

Called from the selected frame generation template to insert this Component's inner structure inside the framing structure.

When framing is used, a selected frame generation template is used as the primary template of the #getElConfig instead of the configured renderTpl. The renderTpl is invoked by this method which is injected into the framing template.

Parameters

Ext.util.Renderable
( )

处理自动渲染。 漂浮的组件可能有ownerCt。如果要限制它们,将它们限制在 ownerCt内,并在本地管理z-index。漂浮的组件总是渲染到document.body。

Ext.util.Renderable
( [Boolean runLayout] )
确保组件添加到document.body。如果组件 渲染到了Ext.getDetachedBody, 组件然后被附加到document.body。 ...

确保组件添加到document.body。如果组件 渲染到了Ext.getDetachedBody, 组件然后被附加到document.body。 重建所有配置的位置。

Parameters

  • runLayout : Boolean (optional)

    设置为true运行组件的布局。

    Defaults to: false

( Object config )private

拓展

Parameters

Ext.util.Renderable
( Number containerIdx )private

This method visits the rendered component tree in a "top-down" order. That is, this code runs on a parent component before running on a child. This method calls the onRender method of each component.

Parameters

  • containerIdx : Number

    The index into the Container items of this Component.

( Object name )private

得到配置项

Parameters

Ext.util.Renderable
( )private

On render, reads an encoded style attribute, "background-position" from the style of this Component's element. This information is memoized based upon the CSS class name of this Component's element. Because child Components are rendered as textual HTML as part of the topmost Container, a dummy div is inserted into the document to receive the document element's CSS class name, and therefore style attributes.

Ext.util.Renderable
( Object table )private

Parameters

得到初始化配置项

Parameters

Ext.util.Renderable
( String/Number/Ext.dom.Element/HTMLElement position ) : HTMLElement
本函数使用传递给onRender的位置参数并返回一个 DOM元素,你能在insertBefore中使用它。 ...

本函数使用传递给onRender的位置参数并返回一个 DOM元素,你能在insertBefore中使用它。

Parameters

Returns

  • HTMLElement

    在insertBefore中使用的DOM元素

Ext.util.Renderable
( Object cls )private

Returns an offscreen div with the same class name as the element this is being rendered. This is because child item rendering takes place in a detached div which, being not part of the document, has no styling.

Parameters

( Object config )private

根据名称判断配置项是否存在

Parameters

( Object config ) : Objectprotected
这个类的初始化配置。典型例子: Ext.define('My.awesome.Class', { // 这是默认配置 config: { name: 'Awesome', isAwes...

这个类的初始化配置。典型例子:

Ext.define('My.awesome.Class', {
    // 这是默认配置
    config: {
        name: 'Awesome',
        isAwesome: true
    },

    constructor: function(config) {
        this.initConfig(config);
    }
});

var awesome = new My.awesome.Class({
    name: 'Super Awesome'
});

alert(awesome.getName()); // 'Super Awesome' 超级棒

Parameters

Returns

  • Object

    mixins 混入原型 键-值对

Ext.util.Renderable
( )private
Ext.util.Renderable
( ) : Objectprivate

Initialized the renderData to be used when rendering the renderTpl.

Returns

  • Object

    Object with keys and values that are going to be applied to the renderTpl

Ext.util.Renderable
( ) : Ext.XTemplateprivate

Initializes the renderTpl.

Returns

( Object name, Object mixinClass )private

内部使用混入预处理器(mixins pre-processor)

Parameters

( Object names, Object callback, Object scope )private

更新配置项

Parameters

( Object fn, Object scope )private

扩展事件

Parameters

Ext.util.Renderable
( Ext.core.Element parentNode, Number containerIdx )protectedtemplate

这个组件的DOM结构创建之后调用的模板方法。

此时, 这个组件(及其所有子组件)的DOM存在, 但是它还没有布局(摆放和调整大小)。

重写这个方法的子类能在渲染时访问DOM结构。 它应该在访问组件的任何子元素之前调用父类的方法。

This is a template method. a hook into the functionality of this class. Feel free to override it in child classes.

Parameters

  • parentNode : Ext.core.Element

    包含封装本组件的元素的父元素。

  • containerIdx : Number

    本组件的父容器的子元素集合中的索引。

( Object config, Object applyIfNotSet )private

设置配置项

Parameters

Ext.util.Renderable
( Object frameTpl )private

Inject a reference to the function which applies the render template into the framing template. The framing template wraps the content.

Parameters

获取从该对象被实例化的类的引用。 请注意不同于 self, this.statics()是独立的作用域,无论this是否运行,总是返回其中的调用类。

Ext.define('My.Cat', {
    statics: {
        totalCreated: 0,
        speciesName: 'Cat' // My.Cat.speciesName = 'Cat'
    },

    constructor: function() {
        var statics = this.statics();

        alert(statics.speciesName);     // 总是等于'Cat',无论'this'是什么,
                                        // 相当于:My.Cat.speciesName

        alert(this.self.speciesName);   // 依赖 'this'

        statics.totalCreated++;
    },

    clone: function() {
        var cloned = new this.self;                      // 依赖 'this'

        cloned.groupName = this.statics().speciesName;   // 相当于: My.Cat.speciesName

        return cloned;
    }
});


Ext.define('My.SnowLeopard', {
    extend: 'My.Cat',

    statics: {
        speciesName: 'Snow Leopard'     // My.SnowLeopard.speciesName = 'Snow Leopard'
    },

    constructor: function() {
        this.callParent();
    }
});

var cat = new My.Cat();                 // alerts 'Cat', 然后提示 'Cat'

var snowLeopard = new My.SnowLeopard(); // alerts 'Cat', 然后提示 'Snow Leopard'

var clone = snowLeopard.clone();
alert(Ext.getClassName(clone));         // alerts 'My.SnowLeopard'
alert(clone.groupName);                 // alerts 'Cat'

alert(My.Cat.totalCreated);             // alerts 3

Returns

配置扩展

Defined By

Static Methods

( Object members )static

方法/属性添加到这个类的原型。

Ext.define('My.awesome.Cat', {
    constructor: function() {
        ...
    }
});

 My.awesome.Cat.implement({
     meow: function() {
        alert('Meowww...');
     }
 });

 var kitty = new My.awesome.Cat;
 kitty.meow();

Parameters

添加/重写这个类的静态属性。

Ext.define('My.cool.Class', {
    ...
});

My.cool.Class.addStatics({
    someProperty: 'someValue',      // My.cool.Class.someProperty = 'someValue'
    method1: function() { ... },    // My.cool.Class.method1 = function() { ... };
    method2: function() { ... }     // My.cool.Class.method2 = function() { ... };
});

Parameters

Returns

( Ext.Base fromClass, Array/String members ) : Ext.Baseprivatestatic
这个类的原型借用另一个类的成员 Ext.define('Bank', { money: '$$$', printMoney: function() { alert('$$$$$$$'); } ...

这个类的原型借用另一个类的成员

Ext.define('Bank', {
    money: '$$$',
    printMoney: function() {
        alert('$$$$$$$');
    }
});

Ext.define('Thief', {
    ...
});

Thief.borrow(Bank, ['money', 'printMoney']);

var steve = new Thief();

alert(steve.money); // alerts '$$$'
steve.printMoney(); // alerts '$$$$$$$'

Parameters

Returns

创建这个类的新实例。

Ext.define('My.cool.Class', {
    ...
});

My.cool.Class.create({
    someConfig: true
});

所有参数传递至类的构造。

Returns

创建现有的原型方法的别名。例如: Ext.define('My.cool.Class', { method1: function() { ... ...

创建现有的原型方法的别名。例如:

Ext.define('My.cool.Class', {
    method1: function() { ... },
    method2: function() { ... }
});

var test = new My.cool.Class();

My.cool.Class.createAlias({
    method3: 'method1',
    method4: 'method2'
});

test.method3(); // test.method1()

My.cool.Class.createAlias('method5', 'method3');

test.method5(); // test.method3() -> test.method1()

Parameters

以字符串格式,获取当前类的名称。

Ext.define('My.cool.Class', {
    constructor: function() {
        alert(this.self.getName()); // alerts 'My.cool.Class'
    }
});

My.cool.Class.getName(); // 'My.cool.Class'

Returns

( Object members ) : Ext.Basedeprecatedstatic

重写这个类的成员。通过callParent重写的方法可以调用。

Ext.define('My.Cat', {
    constructor: function() {
        alert("I'm a cat!");
    }
});

My.Cat.override({
    constructor: function() {
        alert("I'm going to be a cat!");

        this.callParent(arguments);

        alert("Meeeeoooowwww");
    }
});

var kitty = new My.Cat(); // alerts "I'm going to be a cat!我要成为一只猫!"
                          // alerts "I'm a cat!我是一只猫!"
                          // alerts "Meeeeoooowwww"

在4.1版本, 直接利用这种方法已经过时了。 使用 Ext.define 代替:

Ext.define('My.CatOverride', {
    override: 'My.Cat',
    constructor: function() {
        alert("I'm going to be a cat!");

        this.callParent(arguments);

        alert("Meeeeoooowwww");
    }
});

以上完成了相同的结果,但可以由Ext.Loader重写, 其目标类和生成过程中,可以决定是否需要根据目标类所需的状态覆盖管理(My.Cat)。

This method has been deprecated since 4.1.0

使用 Ext.define 代替

Parameters

  • members : Object

    添加到这个类的属性。 这应当被指定为一个对象包含一个或多个属性的文字。

Returns