Extjs 4.1 - 如何在initComponent函数中创建组件

4

我有一个面板,就像这样

 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个回答

4
你正在使用Ext.create() 函数,用于创建你的类的实例。在使用Ext.define()函数定义类时可以使用initComponent方法,但我不确定使用Ext.create()方法时initComponent函数是否有效。

例如,请参阅下面的代码,它将被执行:

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');

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接