2011-05-30 27 views
2

我使用ExtJs4我試圖延長Ext.form.field.ComboBox象下面這樣:嘗試擴展ExtJs ComboBox時出錯 - 「無法讀取'null'的屬性'dom'?

Ext.define('GenericCombo', { 
    extend: 'Ext.form.field.ComboBox', 
    alias: 'widget.genericcombo', 

    //the constructor 
    constructor: function(config) { 

    var store = new Ext.data.JsonStore({ 
     fields: ['Key', 'Value'], 
     data : config.combodata || [] 
    });//new Ext.data.Store 

    Ext.apply(this, config, { 
     store: store, 
     displayField: 'Value', 
     valueField: 'Key', 
     queryMode: 'local', 
     emptyText:'Select a value...' 
    }); 

    this.callParent([this]); 

    }//end constructor 

});//end Ext.define 

的數據爲存儲即config.combodata返回JSON格式如下圖所示:

"combodata":[ 
      {"Key":"","Value":"<None>"}, 
      {"Key":"!#","Value":"Dr"}, 
      {"Key":"!$","Value":"Miss"} 
     ] 

不過我得到ext-all-debug的行61312的錯誤。
(在renderActiveError方法中)。

錯誤:Uncaught TypeError: Cannot read property 'dom' of null

線61312:

me.errorEl.dom.innerHTML = activeError; 

我失去的東西在這裏很明顯?

編輯:添加一些代碼,我實例化它:
其實我實例化組合框動態地即服務器動態地返回一些ExtJS的代碼以JSON格式如下圖所示:

{ 
    "anchor":"50%", 
    "autoScroll":false, 
    "border":false, 
    "combodata":[ 
      {"Key":"","Value":"<None>"}, 
      {"Key":"!#","Value":"Dr"} 
     ], 
    "fieldLabel":"Title", 
    "name":"3820", 
    "value":"!)", 
    "xtype":"genericcombo" 
} 

但是當我嘗試硬編碼它,我得到相同的錯誤。硬編碼的例子:

  xtype: 'form', 
      title: 'A Form', 
      items:[{ 
        xtype: 'genericcombo', 
        fieldLabel: 'Test', 
        combodata: [{Key: 'one', Value: 'two'}] 
        }] 
+0

你能證明你在哪裏實例化它的代碼? – JamesHalsall 2011-05-30 16:16:18

+0

@Jaitsu:我已經添加了一些更多的代碼來解釋我如何實例化它。 – shane87 2011-05-30 16:32:46

回答

3

我打電話

this.callParent([this]); //Which is wrong and caused my error. 

正確的方法是調用

this.callParent([arguments]); 
2

嘗試......你constructorinitComponent方法移動的一切。然後在你的constructor需要調用父類的constructor ...

constructor : function(config) { 
    GenericCombo.superclass.constructor.apply(this,new Array(config); 
} 

我也會考慮您的命名空間組件...像Ext.ux.GenericCombo會更適合。

+0

感謝您的回答。然而,這不起作用,因爲我仍然有同樣的錯誤!任何其他想法? – shane87 2011-05-31 08:45:19

+0

它嵌套的組件的xtype是什麼? – JamesHalsall 2011-05-31 09:21:27

+0

這是一個表單中的項目.. – shane87 2011-05-31 09:25:20

相關問題