尝试扩展 ExtJs ComboBox 时出错 - “无法读取属性‘dom’”为空”?
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我正在打电话
正确的方法是打电话
I was calling
The correct way is to call
试试这个...将
构造函数
中的所有内容移至initComponent
方法。然后在您的构造函数
中,您需要调用父级的构造函数
...我还会考虑为您的组件命名空间...类似于
Ext.ux.GenericCombo
code> 会更适合。Try this... move everything in your
constructor
to theinitComponent
method. Then in yourconstructor
you need to call the parent'sconstructor
...I would also consider namespacing your component... something like
Ext.ux.GenericCombo
would be better suited.