2011-06-27 79 views
0

我想創建工廠函數按照factory-functions-in-ext-extensions, 下面是我的代碼問題與註冊的xtype

Ext.ns('MyApp'); 

MyApp.SubmitButton = Ext.extend(Ext.Button, { 
    text:'Submit' 
    ,iconCls:'icon-disk' 
    ,initComponent:function() { 
     MyApp.SubmitButton.superclass.initComponent.apply(this, arguments); 
    } // eo function initComponent 
}); // eo extend 



var btn = new MyApp.SubmitButton(); 
Ext.reg('submitbutton1',btn);//this is not working 

Ext.reg('submitbutton', MyApp.SubmitButton);//this works 

var win1; 
if(!win1) { 
     win1 = new Ext.Window({ 
      title  : 'title', 
      closeAction : 'hide', 
      autoHeight : true, 
      autoWidth : true, 
      height  : 300, 
      width  : 500, 
      items  : [{xtype:'submitbutton1',id:'submitbutton'}] 
     }); 
    } 
win1.show(); 

當我運行這個它拋出錯誤「B [d.xtype || E]是不是構造函數「

回答

2

您不能使用類的實例來註冊xtype。你必須使用它的類名。內線不跟蹤您正在創建的實例,而只是註冊自定義組件類 - 這樣你可以用這樣的方式:

var button = new MyApp.SubmitButton({ 
     id : 'submitbutton' 
    }); 

OR,

{ 
    xtype : 'submitbutton', 
    id:'submitbutton' 
} 

兩者都是相同的。檢查Saki的this article獲取更多信息。