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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6178418/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 19:47:02  来源:igfitidea点击:

Error trying to extend ExtJs ComboBox - "Cannot read property 'dom' of null"?

javascriptextjsnullextjs4

提问by shane87

I'm using ExtJs4 and I'm trying to extend the Ext.form.field.ComboBoxlike below:

我正在使用 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

The data for the store i.e. config.combodatais returned in JSON format like below:

商店 ie 的数据以config.combodataJSON 格式返回,如下所示:

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

However I get an error on line 61312of ext-all-debug.
(inside the renderActiveError method).

但是我在61312ext-all-debug线上得到一个错误。
(在 renderActiveError 方法中)。

Error: Uncaught TypeError: Cannot read property 'dom' of null

错误: Uncaught TypeError: Cannot read property 'dom' of null

Line 61312 :

第 61312 行:

me.errorEl.dom.innerHTML = activeError;

Am I missing something obvious here?

我在这里遗漏了一些明显的东西吗?

EDIT: Adding some code where I instantiate it:
I actually instantiate the combobox dynamically i.e. The server returns some extjs code dynamically in JSON format like below:

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

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

However When i try to hardcode it i get the same error. Hardcoded example:

但是,当我尝试对其进行硬编码时,我得到了同样的错误。硬编码示例:

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

回答by shane87

I was calling

我在打电话

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

The correct way is to call

正确的方法是调用

this.callParent([arguments]);

回答by JamesHalsall

Try this... move everything in your constructorto the initComponentmethod. Then in your constructoryou need to call the parent's constructor...

在尝试......举动一切你constructorinitComponent方法。然后在constructor你需要打电话给父母的constructor...

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

I would also consider namespacing your component... something like Ext.ux.GenericCombowould be better suited.

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