I have created a model in ExtJS and then created another model which extends the first model. When use the second model in a store, I am getting JavaScript error.
TypeError: this.type.convert is not a function
this.defaultValue = this.type.convert(this.defaultValue);
-- Model--
Ext.define('myModel.FirstModel', {
extend: 'Ext.data.Model',
fields: [
{ name: 'ID' },
{ name: 'Name' },
{ name: 'IsSelected', type: 'bool', defaultValue: false },
{ name: 'IsUpdated', type: 'bool', defaultValue: false },
]
});
--Second model--
Ext.define('myModel.TreeModel', {
extend: 'myModel.FirstModel',
fields: [
{ name: 'leaf', type: 'bool', defaultValue: false },
{ name: 'expanded', type: 'bool', defaultValue: false }
]
});
--Store --
Ext.define('myStore.TreeStore', {
extend: 'Ext.data.TreeStore',
requires: ['myModel.TreeModel'],
model: 'myModel.TreeModel',
autoLoad: false,
proxy: {
type: 'memory'
}
});
** If I do not extend from first model and just copy paste all the fields of first model into second model. I am getting the desired result. What is the cause of the error? What is the right way to extend a model **
Your way is the way... So, upgrade your version of Ext! The 4.1.0 is the only one I found that is concerned with this issue.
Or you can work around the problem by adding this line at the beginning of your code:
Or you can work around it by ensuring all your inherited fields have either a
defaultValue
or aconvert
method:Oh, and don't hesitate to give your precise version of Ext, even if you don't think it should matter with your question... One never knows!