Pages

Tuesday, October 5, 2010

Extjs Store not loading

I recently came across the problem of my Extjs Store not loading anything, with no apparent errors. My Ext.data.Store loads data from a remote server and uses a Ext.data.ArrayReader with a converter for one of the fields, like:

    var genericFeaturesStore = new Ext.data.Store({
    proxy: new Ext.data.HttpProxy({url: 'getRecords.do'}),

    reader: new Ext.data.ArrayReader({}, [

        { name: 'title' },
        { name: 'records', convert : convertRecords}
    ]),
    ...
    });

The converter looks like this:

    var convertRecords = function(v, record) {
        for (var i = 0; i < v.length; i++) {
            v[i] = new Record(
                    v[i].title,
                    v[i].description,
                    v[i].serviceType,
                    v[i].serviceURLs,
                    v[i].keywords);
        }
        return v;
    };


The problem I had was that the convertRecords() seemed to begin execution but not complete, although the application was not stuck but appeared as if convertRecords() had returned.


The solution, which should help for any generic Store loading (or not loading) problem:

    genericFeaturesStore.on({
        'load': {
            fn: function(store, records, options) {
                alert("load");
            },
            scope: this
        },
        'loadexception': {
            fn: function(obj, options, response, e) {
                alert("error: "+e);
            },
            scope: this
        }
    });


This allowed me to see that it was throwing an error because it couldn't find the serviceType for one of the many records.
              

0 comments:

Post a Comment

 
Powered by Blogger