0

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 **

4

1 回答 1

0

你的方式就是方式......所以,升级你的 Ext 版本!4.1.0 是我发现的唯一一个与此问题有关的版本。

或者,您可以通过在代码开头添加此行来解决此问题:

Ext.data.Types.AUTO.convert = function(v) {return v;};

或者,您可以通过确保所有继承的字段都具有 adefaultValueconvert方法来解决它:

Ext.define('myModel.FirstModel', {
    extend: 'Ext.data.Model',
    fields: [
        { name: 'ID', defaultValue: null },
        { name: 'Name', defaultValue: null },
        { name: 'IsSelected', type: 'bool', defaultValue: false },
        { name: 'IsUpdated', type: 'bool', defaultValue: false },
    ]
});

哦,不要犹豫,给出你的 Ext 的精确版本,即使你认为这与你的问题无关......永远不会知道!

于 2013-12-17T11:43:57.990 回答