尝试扩展ExtJs ComboBox时出错 - “无法读取null的属性'dom'”?

时间:2011-05-30 16:00:27

标签: javascript extjs null extjs4

我正在使用ExtJs4而我正在尝试扩展Ext.form.field.ComboBox,如下所示:

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;

我错过了一些明显的东西吗?

编辑:在我实例化的地方添加一些代码:
我实际上是动态地实例化组合框,即服务器以JSON格式动态返回一些extjs代码,如下所示:

 {
    "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'}]
                  }]

2 个答案:

答案 0 :(得分:3)

我正在打电话

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

正确的方法是致电

this.callParent([arguments]);

答案 1 :(得分:2)

尝试此操作...将constructor中的所有内容移至initComponent方法。然后在您的constructor中,您需要致电父母的constructor ...

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

我还会考虑命名空间你的组件... Ext.ux.GenericCombo之类的东西会更适合。