1. #1
    Sencha User
    Join Date
    Nov 2011
    Location
    Bengaluru
    Posts
    12
    Vote Rating
    0
    soubhagya ranjan is on a distinguished road

      0  

    Default problem in loading the json object into the jsonstore

    problem in loading the json object into the jsonstore


    Hi all,

    I m trying to load the jsonstore from a json object using asynchronous callback function.I am not able to loading it in the store, it is showing the following error.

    Uncaught TypeError: Cannot call method 'loadData' of undefined


    My code is as follows

    Code:
    window.generateData = function(year,quarter) {
        var data;
        var linePlot;
        var lplot;
        var month1Label;
        var month1Value;
        var month2Label;
        var month2Value;
        var month3Label;
        var month3Value;
        var jsonReq={"rootCauseInput":{"year":year,"quarter":quarter}};
        var jsonReqObj = Ext.util.JSON.encode(jsonReq);
        Ext.Ajax.request({
            url: "http://localhost:8080/cits/services/CitsService/getUnknownRootCauseByMonth",
            method: 'POST',
            headers: {'Content-Type': 'application/json'},
            jsonData: jsonReqObj,
          success: function(responseObject){
            var dataObj = Ext.decode(responseObject.responseText);
            alert(responseObject.responseText);
            console.info(responseObject.responseText);
            var xaxis=dataObj.xaxis;
            alert(xaxis);
            var yaxis=dataObj.yaxis;
            alert(yaxis);
             linePlot=dataObj.lineGraphPlotsList;
             lplot=linePlot.lineGraphPlots;
             month1Label=lplot[0].label;
             month1Value=parseInt(lplot[0].value);
             month2Label=lplot[1].label;
             month2Value=parseInt(lplot[1].value);
             month3Label=lplot[2].label;
             month3Value=parseInt(lplot[2].value);
            alert(month1Label);    
            alert(month1Value);    
            alert(month2Label);    
            alert(month2Value);    
            alert(month3Label);    
            alert(month3Value);        
            var store = Ext.getCmp('store1');
            if (dataObj.lineGraphPlotsList.lineGraphPlots) {
                if (dataObj.lineGraphPlotsList.lineGraphPlots.length > 0) {
                    store.loadData(dataObj.lineGraphPlotsList.lineGraphPlots, false);
                }}         
          },  
             failure: function(responseObject){
                     alert("error");                 
                }
            
            });
    
    
    };
    
    var storepie10 = new Ext.data.JsonStore({
       fields: ['label','value'],
        data: generateData(11,"Q4")
    });

    I am getting the following "responseObject.responseText"

    {"xaxis":null,"yaxis":null,"lineGraphPlotsList":{"lineGraphPlots":[{"label":"JUN","value":"0"},{"label":"MAY","value":"0"},{"label":"JUL","value":"1"}]}}

    I can also get the values in alert inside the success function.

    please help me
    thanks in advance

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,646
    Vote Rating
    899
    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


    1. You are trying to execute the function to return data onto your JsonStore except it won't be returning anything.
    2. You should create your JsonStore using new Ext.data.JsonStore, you should use Ext.create('Ext.data.JsonStore', {...})

    Further.. I'm not sure why you are using an Ajax call when you can do this in a proxy. I know you are modifying the incoming JSON but you can do this by overriding the JsonReader. Therefore you have all the methods on the Store that can be used to load more data.
    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
    Nov 2011
    Location
    Bengaluru
    Posts
    12
    Vote Rating
    0
    soubhagya ranjan is on a distinguished road

      0  

    Default


    Hi mitchellsimoens ,

    Thanks for looking into my problem.

    I m using this asynchronous ajax call because i m calling a rest web services which will take the url and also the input parameter as follows.


    var jsonReq={"rootCauseInput":{"year":year,"quarter":quarter}};var jsonReqObj = Ext.util.JSON.encode(jsonReq);url: "http://localhost:8080/cits/services/CitsService/getUnknownRootCauseByMonth",



    can i use this request inside a proxy like follows.

    Code:
    var store= new Ext.data.JsonStore({
    		  fields: ['label','value' ],
    		  autoLoad: true,
    		  method:'post',
    		  proxy: {
    		        type: 'ajax',
                            var jsonReq={"rootCauseInput":{"year":year,"quarter":quarter}};
                            var jsonReqObj = Ext.util.JSON.encode(jsonReq);
    
                            url: "http://localhost:8080/cits/services/CitsService/getUnknownRootCauseByMonth",
                        reader: {
    		            type: 'json', 
    		            root  : 'lineGraphPlotsList',
    		            record: 'lineGraphPlots'
    		        }
    		        }
    		      });
    	
       barstore.load({
     });
    please help me
    thanks

Thread Participants: 1