PDA

View Full Version : Is it possible to use Ext.data.JsonReader independent/without associated to a Proxy?



cpremkumar
23 Feb 2012, 3:37 AM
Hi,

I tried to use Ext.data.JsonReader without tied to a proxy, it throws me following error,



Uncaught TypeError: Object [object Object] has no method 'getTotal'


Ext.data.Reader.Ext.extend.readRecordssencha-touch-debug.js:9479

Ext.data.JsonReader.Ext.extend.readRecordssencha-touch-debug.js:9766
handleYelpResultshcController.js:279
(anonymous function)




Here is my code,

The call back function handleYelpResults gets fired giving the yelp results within which I'm trying to use the Ext.data.JsonReader to read the JSON object.



function handleYelpResults(data) {
console.log('yelp results: ' + data.businesses);
if(data.message.text == "OK") {
var config = {
root: 'businesses'
};
var jsonReader = new Ext.data.JsonReader(config);
jsonReader.readRecords(data);
}
}


Could someone clarify me if I can use Ext.data.JsonReader independently/without tying it to any proxy?

If I'm doing something wrong with my code, please let me know.

Thanks,
Prem

mitchellsimoens
23 Feb 2012, 9:42 AM
Why would you want to? If you just want to decode a JSON string to a JavaScript object just use Ext.decode.

cpremkumar
24 Feb 2012, 1:25 AM
Hi Mitchell,

Thanks for the response. I was trying to get the JSON object from the Yelp response using JsonReader. As per your suggestion I tried to use Ext.decode, but I'm seeing following error,

Uncaught SyntaxError: Unexpected token ILLEGAL

Ext.util.JSON.decodesencha-touch-debug.js:14583 (http://127.0.0.1:8020/testHC/www/lib/sencha-touch-debug.js)

Here is my code,



function handleYelpResults(data) {
console.log('yelp results: ' + data);
if(data.message.text == "OK") {
var decodedJsonObject = Ext.decode(data);
console.log(decodedJsonObject);
}
}


Am I using it correctly here? The above function 'handleYelpResults' would be called when I get the response from Yelp server.

Thanks,
Prem

mitchellsimoens
24 Feb 2012, 5:00 AM
What is data? Have you checked to see if data is the JSON or just the response?

cpremkumar
6 Mar 2012, 2:34 AM
Hi Mitchell,

I was able to solve this problem. I was trying to use scripttag proxy method manually to deal with Yelp v2 but it wasn't working.

Now I'm using JSONP request (Ext.util.JSONP.request) and this solves my purpose.

Thanks for your help.

Thanks,
Prem