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

时间:2013-10-09 06:52:00

标签: extjs extjs4.1

我有一个像

这样的小组
 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 个答案:

答案 0 :(得分:4)

您正在使用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');