tags:

views:

554

answers:

1

Hi,

Ive been stuck with this issue for some time

My JSon store fields need to retrieve some more info:

 { name: "ExpirationDate", convert: convertDate },
 { name: "AffectedObject", convert: GetValue }, 

The date method is working fine but the result from GetValue is not being rendered on the grid even though the code is working and returning the correct value (either with or without JSON):

function GetValue(v) {
    var conn = new Ext.data.Connection();
    conn.request({
        url: 'test/GetObjectByID',
        method: 'POST',
        params: { id: v },
        scriptTag: true,
        success: function (response) {
            console.log(response.responseText);
            ReturnResult(response.responseText);
        },
        failure: function () {
            Ext.Msg.alert('Status', 'Something went wrong');
        }
    });


function ReturnResult(str) {
    return Ext.util.JSON.decode(str.toString());
}

Any idea why the result is not not showing?

A: 

The 'convert' property is expecting an immediate return value. Your GetValue function is issuing an asynchronous request and then immediately returning nothing. At some arbitrary point in the future after the request completes the 'success' function is called, but it is no longer connected to the original call so any value it may return is meaningless.

Though you could make it work by replacing the use of Ext.data.Connection with manually constructed synchronous requests, I recommend reconsidering the mechanism by which you are getting this data. Issuing a separate request for every record in your data store is less than optimal.

The best solution is to bring that additional data in on the server side and include it in the response to the store proxy's initial request. If that cannot be done then you can try listening to the store's 'load' event and performing conversion for all loaded records with a single request. Any grids or other views you have reading from the store may have to be configured to display dummy text in place of the missing data until the conversion request completes.

owlness
Thanks owlness,Appreciate your answer. I understand what to use Connection for now, thought it was Store configuration problem. My store JSON can include all the values actually.It's my first big project and my first time with Ext but I'm wondering if it was the right decision due to the lack of support.
CohenA