2013-10-09 49 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');