0
votes

I'm still new to ExtJS and I cannot figure out how to get code-generated data into a Model.

I have some complicated data that will be the result of mixing two ajax calls together. The resulting data will be json-like in the format that ExtJS expects.

I'm not sure if I need an ExtJS Model, Store, Proxy, Loader, Reader, Filter, or any combination of these interlocked pieces.

What I want is to populate data in a Model with a regular javascript function. The function must defer to the asyncronous requests. I suppose it will pass the data back to the Model or Store using some 'success' callback? Or just assign the data directly into the store?

Is there an example of creating this type of data? Will it require subclassing any of the ExtJS data objects, or can it be done by configuring the existing class types?

1

1 Answers

0
votes

If you are going to fetch the data yourself, you don't need Proxy, or DataReader. Bypass both of them by never calling Ext.data.Store.load(), and always calling Ext.data.Store.loadData() http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Store-method-loadData.

Ext.define('User', {
    extend: 'Ext.data.Model',
    fields: [
        {name: 'name',  type: 'string'},
        {name: 'age',   type: 'int'},
        {name: 'phone', type: 'string'},
        {name: 'alive', type: 'boolean', defaultValue: true}
    ]
});

var store = Ext.create('Ext.data.Store', { model: 'User'});

store.loadData([{
    name: 'Jack',
    age: 25,
    phone: '731.234.3568'
}]);