【问题标题】:Extjs 4.1 - How to create item in initComponent functionExtjs 4.1 - 如何在 initComponent 函数中创建项目
【发布时间】: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/

【问题讨论】:

    标签: extjs extjs4.1


    【解决方案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');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-18
      • 2011-03-11
      相关资源
      最近更新 更多