Error trying to extend ExtJs ComboBox - "Cannot read property 'dom' of null"?
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.
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'}]
}]
I was calling
this.callParent([this]); //Which is wrong and caused my error.
The correct way is to call
this.callParent([arguments]);
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.
精彩评论