2012-06-20 48 views
0

目前我正在試圖添加自定義按鈕,將能夠當過用戶想要添加使用EXTJS 4.一個新的按鈕ExtJS的4:如何添加按鈕,自定義任何形式

這裏是調用我想TimeButton.js文件用來創建按鈕

Ext.namespace("Ext.controls"); 

Ext.create('Ext.Button', { 
text: 'Time', 
renderTo: Ext.getBody(), 
handler: function() { 
    alert('The current time is '+Date()) 
} 
}); 

Ext.reg('timebutton', Ext.controls.TimeButton); 

但是當過我嘗試將其添加到任何形式我碰到下面的錯誤

types[config.xtype || defaultType] is not a constructor 

或者倒不如做些什麼像這樣

Ext.controls.TimeButton = Ext.extend(Ext.Panel, { 

initComponent: function(){ 


    Ext.apply(this, {      
      frame: true 
      ,height: 330  
      ,layout: 'border' 
      ,layout: 'column' 
      ,split: true 
      ,cls: 'DocumentWindow' 
      ,items: [] 

    }); 

    this.documentGrid = new Ext.controls.DocumentGrid({height: 220, 
       agentId : this.agentId, 
       columnWidth: 0.5}) 

    Ext.controls.DocumentPanel.superclass.initComponent.apply(this, arguments); 


} 

從我理解的情況來看,當嘗試實例化(創建)一個不存在的組件時,卻發現錯誤可能在哪裏!在我發佈的代碼中是否有錯誤?

回答

0

將您的按鈕定義爲一個類,通過提供alias屬性將其註冊爲與xtype一起使用,並在父容器中將其實例化爲itemsHere就是一個例子。

+0

沒有,沒有工作,仍然得到了相同的錯誤信息 – flexinIT

+0

它必須。這個例子是否適合你?你是否刪除了舊代碼並換成了新代碼? –

相關問題