问题描述:

The story is :

I have a complex form with about 10 combo-boxes. Each of them fetch their binding list from a different store (Restful ones). for example :

  • /api/projects/activeyears
  • /api/users/managers
  • /api/projects/availableDates
  • ...

My server side technology (Microsoft WebApi 2) supports batch requests gracefully (described here : http://bradwilson.typepad.com/blog/2012/06/batching-handler-for-web-api.html) .

I want to know if I can do it in ExtJs or not? If yes please tell me how but if your answer is no, can you give me an alternative solution? Requesting 10 different stores makes the form to load too slowly (when all major browsers just make 2 parallel requests at a same time, so I should wait for at least 5 serial requests).

Thanks in advance

网友答案:

Server-side you can use batch requests (aggregate 2 x 5 requests or 3+3+4). Ideally you return something like:

{
    success: true,
    activeyears: [ ... ],
    managers: [ ... ],
    availableDates: [ ... ], 
    ...
}

From ExtJS point of view this is an Ajax-request without a connection to a store or proxy.

In success you have something like this:

Ext.Ajax.request({
    url: '/api/myAggregatedRequest1',
    method: 'GET',
    success: function (result, request) {
        var jsonResp;

        jsonResp = Ext.decode(result.responseText);
        if (jsonResp.success) {
            myActiveYearsStore.loadData(jsonResp.activeyears);
            myManagersStore.loadData(jsonResp.managers);
            myAvailableDatesStore.loadData(jsonResp.availableDates);

            // ... trigger some event

        } else {
            // ... error handling
        }
    },
    failure: function (result, request) {
        // ... error handling
    }
});
相关阅读:
Top