Search code examples
javascriptsencha-touchextjs

How to retrieve Ext.data.JsonStore data in sencha


I have the following code -

var options = new Ext.data.JsonStore({
            model: 'options_model',
            data: [
                { id: 1, option1: 'Alope', status1: 'true',option2: 'Option2', status2: 'false',option3: 'Option3', status: 'false',option4: 'Option4', status4: 'false' }
                  ]
        });

Now how can I retrieve data of option ???


Solution

  • I suggest you put your data into maybe a filename.json file (this is to maintain the scalability and integrity of your code).

    Anyway, wherever it is you store your data, this is the code you need:

    Ext.Ajax.request({
        url: 'path_to_ur_json_file_wrt_html_file/filename.json',    //in my case it was data/xyz.json  since my folder layout was : abc.html, app, data, lib, stylesheets; and my data.json was in the data folder :)
        timeout:3000,      //how long it shud try to retrieve data in ms
        method:'GET',
        success: function(xhr) {
            jsonData = Ext.util.JSON.decode(xhr.responseText);
            var data4u = jsonData.data[0].option1;
        }
    });