PDA

View Full Version : how do I get the whole JSON raw data from the JSONStore? I



ananthk
11 Feb 2013, 2:19 PM
How to asign the raw JSON from JSON store to a variable outside the Store definition-

EXTJS4
// var raw = { data: [{"app":"test1","X":1.82,"Y":54.44},
// {"app":"test2","X":1.76,"Y":50.53},
// {"app":"test3","X":1.7,"Y":47.37},
// {"app":"test4","X":1.42,"Y":40.15},
// {"app":"test5","X":1.19,"Y":35.52}] };

var store = new Ext.data.JsonStore({
storeId: 'myStore',
model: 'MeanVariance',
proxy: {
type: 'rest',
url:url,

reader: {
type: 'json',
root: 'data'

}
}

Hi I need to get the JSON Data as above. I am getting it from the server side. But How to I get this JSON string assgined to a variable so that I can use it anywhere I want to . Thanks!

slemmon
11 Feb 2013, 10:46 PM
store.getProxy().getReader().rawData
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.reader.Reader-property-rawData

ananthk
12 Feb 2013, 11:44 AM
Thanks. I got the rawdata as array [object, Object], [object, Object], [object, Object], > I see this in the data property. How do I convert this to my required JSON string that I defined.

Thanks!

slemmon
12 Feb 2013, 11:49 AM
var rawObj = store.getProxy().getReader().rawData;
var rawString = Ext.encode(rawObj); // turns a javascript object into a string

http://docs.sencha.com/ext-js/4-1/#!/api/Ext-method-encode

ananthk
13 Feb 2013, 7:33 AM
Thaks so much. It worked