Extjs 4.1 - 如何在 initComponent 函数中创建项目

Posted

技术标签:

【中文标题】Extjs 4.1 - 如何在 initComponent 函数中创建项目【英文标题】:Extjs 4.1 - How to create item in initComponent function 【发布时间】:2013-10-09 06:52:00 【问题描述】:

我有一个类似的面板

 var filterPanel = Ext.create('Ext.panel.Panel', 
        bodyPadding: 5,
        width: 300,
        myValue:5,
        title: 'Filters',
        initComponent: function() 
            this.items = [
                xtype: 'textfield',
                value: this.myValue
            ];
            this.callParent();
        
        renderTo: Ext.getBody()
    ); 

我尝试创建一个具有xtype: 'textfield' 且值为面板的myValue 的项目。但那是失败的。

如何做到这一点,谢谢。 这是我的示例文本 http://jsfiddle.net/4Cmuk/

【问题讨论】:

【参考方案1】:

您正在使用Ext.create() 函数,该函数用于创建您的类的实例。 initComponent 方法可以在使用Ext.define() 函数定义类时使用,我不确定但initComponent 函数不能使用Ext.create() 方法工作。

例如看下面的代码,它会被执行:

Ext.define('customPanel', 
        extend: 'Ext.panel.Panel',
        bodyPadding: 5,
        width: 300,
        myValue:5,
        title: 'Filters',
        initComponent: function() 
            this.items = [
                xtype: 'textfield',
                value: this.myValue
            ];
            this.callParent(arguments);
        ,
        renderTo: Ext.getBody()
    ); 

Ext.create('customPanel');

【讨论】:

以上是关于Extjs 4.1 - 如何在 initComponent 函数中创建项目的主要内容,如果未能解决你的问题,请参考以下文章

Extjs 4.1 - 如何在 initComponent 函数中创建项目

ExtJS 4.1:如何在组合框中设置预选项目?

Extjs 4.1 - 如何在网格面板中显示 html 数据

在 ExtJS 4.1 中单击外部窗口时如何关闭窗口?

extjs 4.1 如何在 xtemplate 中显示编号和项目符号

Extjs 4.1 - 如何在树形面板中设置 singleExpand false