views:

1820

answers:

4

I have an ExtJS based application. When editing an object, an ExtJS window appears with a number of tabs. Three of these tabs have Ext GridPanels, each showing a different type of data. Currently each GridPanel has it's own JsonStore, meaning four total AJAX requests to the server -- one for the javascript to create the window, and one for each of the JsonStores. Is there any way all three JsonStores could read from one AJAX call? I can easily combine all the JSON data, each one currently has a different root property.

Edit: This is Ext 2.2, not Ext 3.

+1  A: 

You may be able to do this using Ext.Direct, where you can make multiple requests during a single connection.

Steve -Cutter- Blades
+3  A: 

You could get the JSON directly with an AjaxRequest, and then pass it to the loadData() method of each JSONStore.

David Winslow
A: 

Maybe HTTP caching can help you out. Combine your json data, make sure your JsonStores are using GET, and watch Firebug to be sure the 2nd and 3rd requests are not going to the server. You may need to set a far-future expires header in that json response, which may be no good if you expect that data to change often.

Jonathan Julian
+2  A: 

The javascript object created from the JSON response is available in yourStore.reader.jsonData when the store's load event is fired. For example:

yourStore.on('load', function(firstStore) {
   var data = firstStore.reader.jsonData;
   otherStore.loadData(data);
   thirdStore.loadData(data);
}

EDIT: To clarify, each store would need a separate root property (which you are already doing) so they'd each get the data intended.

{
   "firstRoot": [...],
   "secondRoot": [...],
   "thirdRoot": [...]
}
wes