get json array from extjs.data.store

Posted by jane on January 6th, 2009
  • Hi,

    just wondering how to get the json array from the store?

    I want to retrieve the json array object outside the ajax request or store.

    i tried this but

    var arr;
    var conn = new Ext.data.Connection();
    conn.request({
    url: listSurveyAttemptPath,
    params:{survey_id:1},
    success: createArray,
    failure: function() {
    Ext.Msg.alert('Status', 'Unable to show history at this time. Please try again later.');
    }
    });
    function createArray(response) {
    var obj = Ext.util.JSON.decode(response.responseText);
    arr = obj;
    alert(arr); //<-- this works!
    }
    alert(arr); //<-- this does not work!

    the arr object inside the function createArray is correct however i cannot access it outside the function.

    but i need to manipulate the arr outside the function.

    else how to get the json array from the Ext.data.store?

    how can i do this?
    any idea?

    Thanks..


  • var obj = Ext.util.JSON.decode(response.responseText);
    arr = obj;

    }


    arr links to the internal obj which gets lost outside the function.
    Simply try

    arr = Ext.util.JSON.decode(response.responseText); Does it work now?

    Anyway alert(arr) will only work, as already said, _after_ the ajax request has been done.


  • Use the "<-- this works!" line! 8-


  • Ajax requests are not synchronous.

    When you try to access it the second time, the ajax request has probably not completed.


  • but i need to use the arr values outside the ajax request. any idea? thanks


  • so any idea how can i get the array itself from servlet?


  • Call the "outside" function from the success handler.

    Ajax is asynchronous. You just have to pick up your processing after the data returns.

    You do get used to it!







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about get json array from extjs.data.store , Please add it free.