Nir Nir - 4 months ago 12
Javascript Question

how to implement Extjs Model that expect to receive List of objects

I define the following Model:

Ext.define('itfm.application.model.SystemHealth', {
extend: 'Ext.data.Model',
fields: [
{name: 'module', type: 'systemModule'},
{name: 'status', type: 'SystemModuleStatus'},
{name: 'lastRun', type: 'long'},
{name: 'lastSuccessfulRun', type: 'long'},
{name: 'nextRun' , type: 'long'},
{name: 'numberOfMinutes', type :'int'},
{name: 'moduleIdentifier' , type : 'string'},
{name: 'duration' , type: 'long'}
]
});


and the data the I expected to receive from the server is:

{
"moduleStatusList": [
{
"module": 2,
"status": 0,
"lastRun": 1373368689143,
"lastSuccessfulRun": 1373368689143,
"nextRun": 1373378686392,
"numberOfMinutes": 159
}
]
}


I'm adding the store:

Ext.define('itfm.application.store.SystemHealth',
{ extend: 'Ext.data.Store', proxy: { autoLoad: true, type: 'rest', reader: { type: 'json' }, api: { read: 'rest/system-health' } } })

Answer

This is how I would define the store in your case, you are missing some of the attributes that are needed:

Ext.define('itfm.application.store.SystemHealth', {
    extend: 'Ext.data.Store',
    model: 'itfm.application.model.SystemHealth',
    proxy: {
        autoLoad: true,
        type: 'rest',
        reader: {
            type: 'json',
            root: 'moduleStatusList'
        },
        api: {
            read: 'rest/system-health'
        }
    }
});
Comments