2
votes

I'm using ExtJs 4.2.1. The records parameter of store's load event is shown as null.

st = Ext.getStore('MyJsonStore');
st.on('load', function(store, records, successful, eOpts) {
    //Block of codes
    var access = records[0].data.access;
    //Block of codes
});
st.load();

The error message is thrown at the console as:-

TypeError: Cannot read property '0' of null

Can anyone help me with this?

4
Can you post your store?Aminesrine

4 Answers

2
votes

What does your model look like? Are you trying to do something with the data before it makes it into the store? If so, you should probably be using a reader in the proxy for the store config like below. Otherwise, @user1896597 answer should be the appropriate one.

Ext.define('MyJsonStore', {
    extend: 'Ext.data.Store',
    model: 'YourModel',
    proxy: {
        type: 'ajax',
        url: '/someurl',
        reader: {
            successProperty: 'success', // if success property
            type: 'json',
            root: 'results', // if root

            // THIS IS THE FUNCTION YOU NEED TO MANIPULATE THE DATA
            getData: function(data){
                Ext.each(data.results, function(rec) {
                    var access = rec.access;
                });

                return data;
            }
        },
        writer: {
            type: 'json'
        }
    }
});
2
votes

Can you try this?

If this isn't working post a JSFiddle, there may be something else wrong with your code.

store.load({
    callback: function(records, operation, success) {
        alert(records.length);
    }
});
1
votes

Try with:

st=Ext.getStore('MyJsonStore');
st.load();
st.on('load',function (store, records, successful, eOpts ){
     //Block of codes
     var access=records[0].data.access;
     //Block of codes
});
0
votes

Maybe is too late to help you, but I found an solution (for the records):

st = Ext.getStore('MyJsonStore');
st.on('load', function(store, records, successful, eOpts) {
    //Block of codes
    var access = records[0].get('access');
    //Block of codes
});
st.load();

This way, you can now have access to data row.