Ext.create()方法浅析

来源:互联网 发布:mac ssh工具 编辑:程序博客网 时间:2024/06/05 11:40

译自:http://docs.sencha.com/extjs/4.2.0/#!/api/Ext-method-create

create( [name], [args] ) : Object

Instantiate a class by either full name, alias or alternate name.

If Ext.Loader is enabled and the class has not been defined yet, it will attempt to load the class via synchronous loading.

For example, all these three lines return the same result:

 // alias var window = Ext.create('widget.window', {     width: 600,     height: 800,     ... }); // alternate name var window = Ext.create('Ext.Window', {     width: 600,     height: 800,     ... }); // full class name var window = Ext.create('Ext.window.Window', {     width: 600,     height: 800,     ... }); // single object with xclass property: var window = Ext.create({     xclass: 'Ext.window.Window', // any valid value for 'name' (above)     width: 600,     height: 800,     ... });

Available since: 3.4.0

Parameters

  • name : String (optional)

    The class name or alias. Can be specified as xclass property if only one object parameter is specified.

  • args : Object... (optional)

    Additional arguments after the name will be passed to the class' constructor.

Returns

  • Object

    instance

//////////////

通过指定的名称 实例化一个类,其中第二个参数 中的 键值对 为 构造器 提供 实例化 时对应的参数名和值。

Ext.create()和Ext.widget()的区别:

Ext.widget

widget( [name], [config] ) : Object

Convenient shorthand to create a widget by its xtype or a config object. See also Ext.ClassManager.instantiateByAlias.

 var button = Ext.widget('button'); // Equivalent to Ext.create('widget.button'); var panel = Ext.widget('panel', { // Equivalent to Ext.create('widget.panel')     title: 'Panel' }); var grid = Ext.widget({     xtype: 'grid',     ... });

If a component instance is passed, it is simply returned.

Available since: 4.0.0

Parameters

  • name : String (optional)

    The xtype of the widget to create.

  • config : Object (optional)

    The configuration object for the widget constructor.

Returns

  • Object

    The widget instance

/////

widget可以通过别名访问 组件:

如下:

Ext.define('cdkj.view.correct.end.CorrectionEndListView',{
extend : 'Ext.grid.Panel',
alias : 'widget.correctCorrectionEndListView',
store : 'correct.CorrectionEndStore',
layout : {
type : 'fit'
},
title : '归档档案列表',

这时我们可以通过:

var view= Ext.widget("correctCorrectionEndListView");

创建一个cdkj.view.correct.end.CorrectionEndListView类的实例。





0 0