PDA

View Full Version : problem in loading the json object into the jsonstore



soubhagya ranjan
30 Nov 2011, 2:13 AM
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



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

mitchellsimoens
30 Nov 2011, 8:30 AM
You are trying to execute the function to return data onto your JsonStore except it won't be returning anything.
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.

soubhagya ranjan
30 Nov 2011, 8:17 PM
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.



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