0
votes

I have a problem creating a store and I need some help. I have a store, created using Ex.define approach and it works just fine. Here is the code:

  Ext.define('path.to.myStore', {
        extend: 'Ext.data.Store',
        model: 'arm4.dict.m.DictBaseModel',
        proxy: {
            type: 'ajax',
            url: 'data/module-dict/PossessionGroundWs/find',

            reader: {
                type: 'json',
                root: 'dataList'
            }
        }
    });

//later
//works fine!
var s =Ext.create('path.to.myStore');
s.load();

Now, the problem is I want to create store dynamically, without Ex.define. This is how I do it:

var s = Ext.create('Ext.data.Store', {
    model: 'arm4.dict.m.DictBaseModel',
    proxy: {
        type: 'ajax',
        url: 'data/module-dict/PossessionGroundWs/find',

        reader: {
            type: 'json',
            root: 'dataList'
        }
    }
});

s.load();

As you can see, it uses exactly the same configuration, but this doesn't work. I get this error:

TypeError: reader.read is not a function    
result = reader.read(me.extractResponseData(response));

When I dig into Extjs code, I can see that reader is not initialized by some reason.

"reader" looks like this:

{
    applyDefaults:true
    root:"dataList"
    type:"json"
}

So, what am I doing wrong? Can you reproduce this error(bug)?

5

5 Answers

3
votes

Can't reproduce this error but I remember someday I had it. Try to define your reader in a separate file like this

Ext.define('My.reader.Default', {
    extend: 'Ext.data.reader.Json',
    alias: 'reader.myreader',

    root: 'dataList'
});

and then

Ext.create('Ext.data.Store', {
    requires: ['My.reader.Default'],
    model: 'arm4.dict.m.DictBaseModel',
    proxy: {
        type: 'ajax',
        url: 'data/module-dict/PossessionGroundWs/find',
        reader: 'myreader'
    }
});

Maybe this will help.

2
votes

I have found the problem. I do not really know if it's a bug or not, but if you create your store with Ext.create(without Ext.define) you have to require your model class prior to creation.

So, this works fine:

Ext.require('arm4.dict.m.DictBaseModel');
//......
var s = Ext.create('Ext.data.Store', {
    model: 'arm4.dict.m.DictBaseModel',
//store definition 
1
votes

Sorry for bumping a years old question, but this page comes quite high in Google when searching for the error TypeError: reader.read is not a function, so I hope it might be useful. I had the same error, which was caused by a store linked to a non-existing model, so please check your model reference for any typo's.

1
votes

Its is a old question but this issue is very common. In my scenario I didn't define the model, I forgot to extend my model with 'Ext.data.Model', After extend it starts working properly.

0
votes

I reproduced the same error when my model definition was wrong. So review that. In my case:

Ext.define('APP.model.web.bdetmclocalidad.BdetMcProvincia', {
    extend: 'Ext.data.Model',
    idProperty : 'idProvincia',
    fields: [
        {name:'codProvincia', type:"string", useNull:true}
        ,{name:'descProvincia', type:"string", useNull:true}
    ],
    proxy : {
        type : 'uxproxy',
        localUrl : 'data/bdetMcProvinciasListado.json',
        remoteUrl : 'bdetmcprovincia'
    }
});


Ext.define('APP.store.web.bdetmcprovincia.BdetMcProvinciaStore', {
    extend : 'Ext.data.Store',
    requires : 'APP.model.web.bdetmcprovincia.BdetMcProvincia',
    model : 'APP.model.web.bdetmcprovincia.BdetMcProvincia',
    filterOnLoad : false,
    remoteSort   : true,
    pageSize     : 25,
    proxy : {
        type : 'uxproxy',
        localUrl : 'data/bdetMcProvinciasListado.json',
        remoteUrl : 'bdetmcprovincia'
    }
});

I make a mistake with the package name (caused by copy & paste): APP.model.web.bdetmclocalidad.BdetMcProvincia is not equal to APP.model.web.bdetmcprovincia.BdetMcProvincia

I hope this help.