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
Error trying to extend ExtJs ComboBox - "Cannot read property 'dom' of null"?
提问by shane87
I'm using ExtJs4 and I'm trying to extend the Ext.form.field.ComboBox
like 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.combodata
is returned in JSON format like below:
商店 ie 的数据以config.combodata
JSON 格式返回,如下所示:
"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).
但是我在61312
ext-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 constructor
to the initComponent
method. Then in your constructor
you need to call the parent's constructor
...
在尝试......举动一切你constructor
的initComponent
方法。然后在constructor
你需要打电话给父母的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.
我也会考虑给你的组件命名空间......类似的东西Ext.ux.GenericCombo
会更适合。