Hybrid View

  1. #1
    Sencha User
    Join Date
    Oct 2012
    Posts
    53
    Vote Rating
    0
    sandeepmnit35 is on a distinguished road

      0  

    Default Store with type memory not loading the data

    Store with type memory not loading the data


    I am getting json response and am trying to put json in store but it is not loading it properly.


    HTML Code:
    Ext.Ajax.request({   
                           url: url,                                               
          success: function(xhr) {                       
       response = Ext.JSON.decode(xhr.responseText.trim());                          //alert(xhr.responseText.trim());                                                  
      for(i=0;i< response.data.length; i++)                                                     {                              instancestore[i] = Ext.create('Ext.data.Store', {           
                           autoLoad: true,                     
                 model: 'RA.model.DataModel',    
                                 proxy: {               
                           type: 'memory',           
                               data: response,      
                                    reader: {          
                                    type: 'json',      
                                        root: 'data'      
                                    }               
                       }         
                         });           
                                                }   
    My Json output is :

    HTML Code:
    {    "data": 
    [{        "0": [{            "DowntimeEvents": 179,            "DowntimeHours": 78355        }]    },    {        "1": [{            "DowntimeEvents": 176,            "DowntimeHours": 97835        }]    },    {        "2": [{            "DowntimeEvents": 140,            "DowntimeHours": 100501        }]    }]}
    I tried below code but it is passing null value of DowntimeEvents and DowntimeHours in the store.
    HTML Code:
     Ext.Ajax.request({    
                                        url: url,     
                                                    success: function(xhr) {   
                           response = Ext.JSON.decode(xhr.responseText.trim());  
                            //alert(xhr.responseText.trim());               
                                         for(i=0;i< response.data.length; i++)                                                     {                            alert(response.data[0].DowntimeEvents);                        
                   
              instancestore[i] = Ext.create('Ext.data.Store', {            
                          autoLoad: true,               
                       model: 'RA.model.DataModel',        
                              data: response.data[i],                 
                     proxy: {            
                              type: 'memory',           
                                                                    reader: {     
                                         type: 'json',       
                                                                         
        }                               
       }                      
            });                               
                            }

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,533
    Vote Rating
    871
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    First off you have some config that are in the wrong place or are not truly valid:

    Code:
    var store = Ext.create('Ext.data.Store', {
        model : 'RA.model.DataModel',
        data  : response,
        proxy : {
            type  : 'memory',
            reader : {
                rootProperty : 'data'
            }
        }
    });
    Your response is a little too nested, instead of this:

    Code:
    {
        "data" : [
            {
                "0" : [
                    {
                        "DowntimeEvents" : 179,
                        "DowntimeHours"  : 78355
                    }
                ]
            },
            {
                "1" : [
                    {
                        "DowntimeEvents" : 176,
                        "DowntimeHours"  : 97835
                    }
                ]
            },
            {
                "2" : [
                    {
                        "DowntimeEvents" : 140,
                        "DowntimeHours"  : 100501
                    }
                ]
            }
        ]
    }
    should really be:

    {
    "data" : [
    {
    "DowntimeEvents" : 179,
    "DowntimeHours" : 78355
    },
    {
    "DowntimeEvents" : 176,
    "DowntimeHours" : 97835
    },
    {
    "DowntimeEvents" : 140,
    "DowntimeHours" : 100501
    }
    ]
    }

    and you are good now.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Oct 2012
    Posts
    53
    Vote Rating
    0
    sandeepmnit35 is on a distinguished road

      0  

    Default


    I need to store data on index basis for different date thats why I am using instance[i] and sending indexes in json response so I can store the data on index basis.

    My json is having data for 3 different date and I am using slider with play button to render the graph for 3 different date so I need to have data on index basis in store .

    Can you please let me know how can I do this?
    Thanks

Thread Participants: 1

Tags for this Thread