ExtJS: Multiple JsonStores from a single AJAX call?

I have an ExtJS based application. When editing an object, an ExtJS window appears with several tabs. Three of these tabs have Ext GridPanels, each of which shows different data types. Currently, each GridPanel has its own JsonStore, which means four common AJAX requests to the server - one for javascript to create a window and one for each of JsonStores. Is there a way that all three JsonStores can read from one AJAX call? I can easily combine all the JSON data, each of which has a different property root.

Edit : this is Ext 2.2, not Ext 3.

+3
source share
5 answers

A javascript object created from a JSON response is available in yourStore.reader.jsonDatawhen the store event is loadfired. For example:

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

EDIT: To clarify, for each repository you will need a separate property root(which you already do) so that each of them gets the data.

{
   "firstRoot": [...],
   "secondRoot": [...],
   "thirdRoot": [...]
}
+3
source

You can get JSON directly using AjaxRequest, and then pass it to the loadData () method for each JSONStore.

+3
source

, Ext.Direct, .

+1

, HTTP- . json, , JsonStores GET Firebug, 2- 3- . , json-, , , .

0
source

Another fantastic way is to use Ext.Data.Connection () as shown below:

var conn = new Ext.data.Connection();
    conn.request({
        url: '/myserver/allInOneAjaxCall',
        method: 'POST',
        params: {
           // if you wish too
        },
        success: function(responseObj) {
            var json = Ext.decode(responseObj.responseText);

           yourStore1.loadData(json.dataForStore1);
           yourStore2.loadData(json.dataForStore2);            

        },
        failure: function(responseObj) {
            var message = Ext.decode(responseObj.responseText).message;
            alert(message);

        }
    });

It worked for me.

0
source

Source: https://habr.com/ru/post/1721099/


All Articles