Lets suppose I have this web application built using extjs4 in my client-side and a Zend framework action controller in server-side. I have array of arrays in server-side that they could be output as JSON to the client.when i want to create only one store,usual way is working like this:
Ext.define('MA.store.AdminResources', {
extend : 'Ext.data.Store',
fields : [ {
name : 'id'
}, {
name : 'name'
} ],
autoLoad : true,
proxy : {
type : 'ajax',
url : './account/adminresources',
reader : {
type : 'json'
//,root : 'users'
}
}
});
what if i wanted to create multiple JSON stores from just A single http request to the server? this server will not receive a remote proxy request per store and one request will be done for ALL stores. Here is an example of my JSON which is returned by server:
{
"adminsettings"{"userid":3333,"primaryemail":"[email protected]","firstname":"","middlename":null}
,"countries":{"AD":"Andorra","AE":"UnitedArabEmirates","AF":"Afghanistan"...}
,"languages":{"aa":"Afar","ab":"Abkhazian","ace":"Achinese","ach":"Acoli"...
}}
How can JSON stores for adminsettings,countries,languages be created with just one http request to the server? perhaps i need to define one proxy and 3 readers?!
As you can see in the documentation you can define store without proxy:
Ext.create('Ext.data.Store', {
model: 'User',
data : [
{firstName: 'Ed', lastName: 'Spencer'},
{firstName: 'Tommy', lastName: 'Maintz'},
{firstName: 'Aaron', lastName: 'Conran'},
{firstName: 'Jamie', lastName: 'Avins'}
]
});
then It's easy to make an ajax request and onSuccess to load data manualy:
Something like this:
adminSettings = Ext.create('Ext.data.Store', {model: AdminSettings});
countries = Ext.create('Ext.data.Store', {model: Country});
Ext.ajax.request({
url: './account/adminresources',
success: function(response) {
var json = Ext.decode(response.responseText);
adminsettings.loadData(json.adminsettings);
countries.loadData(json.countries);
//...
}
});