2011-05-30 46 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

相关问题