尝试扩展 ExtJs ComboBox 时出错 - “无法读取属性‘dom’”为空”?

发布于 2024-11-10 05:29:36 字数 1813 浏览 0 评论 0原文

我正在使用 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 方法内)。

错误:未捕获类型错误:无法读取 null 的属性“dom”

第 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'}]
                  }]

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

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.combodata is returned in JSON format like below:

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

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

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

Line 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:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

捂风挽笑 2024-11-17 05:29:36

我正在打电话

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

正确的方法是打电话

this.callParent([arguments]);

I was calling

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

The correct way is to call

this.callParent([arguments]);
乱世争霸 2024-11-17 05:29:36

试试这个...将构造函数中的所有内容移至initComponent方法。然后在您的构造函数中,您需要调用父级的构造函数...

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

我还会考虑为您的组件命名空间...类似于Ext.ux.GenericCombo code> 会更适合。

Try this... move everything in your constructor to the initComponent method. Then in your constructor you need to call the parent's constructor...

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文