2013-10-09 48 views
3

创建项目我有一个像EXTJS 4.1 - 如何initComponent功能

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/

回答

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