-
10 Aug 2009 9:23 AM #1
JSONReader for JSON with multiple root elements
JSONReader for JSON with multiple root elements
Hello,
I am trying to figure out if there is a way to set up a reader to read multiple root elements.
Currently, my dataStore is setup like this...
// Define Shapes Datastore
// Airport data store
shapeStore =new Ext.data.Store({
url: myUrl,
reader: new Ext.data.JsonReader({
root:'schedshp'
},['type',
'airspace_name',
'start_time',
'end_time',
'style',
'geom'
]),});
I have recently changed the JSON to be like this...
{ "schedshp": [], "astype": [ {"astype": "atcaa"}, {"astype": "arial_rr"}, {"astype": "alert"}, {"astype": "moa"}, {"astype": "other"}, {"astype": "prohibited"}, {"astype": "restricted"}, {"astype": "warning"} ], "acttype": [ {"actype": "active"}, {"actype": "_1hour"}, {"actype": "1h_2h"}, {"actype": "2h_4h"}, {"actype": "4h_8h"} ], "alttype": [ {"alttype": "surf_10"}, {"alttype": "10_17"}, {"alttype": "FL180_FL280"} ] }
In addition to being able to read the "schedshp" root, I'd like to also be able to read the astype, acttype and alttype root elements.
Any help would be much appreciated.
Thanks,
Jim
-
10 Aug 2009 10:02 AM #2
If you are in control of the JSON, why not just create a simple Array of rows container the data for each row?
Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
10 Aug 2009 10:12 AM #3
I think that'd work... but how about something like this
I think that'd work... but how about something like this
Hello,
While you were responding I found this somewhere in the forum...
ds1.load({
callback: function(){
ds2.loadData(ds1.reader.jsonData);
}
});
Would something like this work too?
Thanks,
Jim
-
10 Aug 2009 10:18 AM #4Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 41
That code is used to load 2 stores from the same request.
Is that what you want or did you want to load one store with data from 2 roots.
-
10 Aug 2009 10:30 AM #5
More info....
More info....
Currently, the first datastore makes the server request. The JSON being returned has multiple roots. If the second datastore could reference a different root, then I'd be fine. Is that possible?
Thanks,
Jim
-
10 Aug 2009 10:45 AM #6Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 41
Yes, simply use the code you found.
-
10 Aug 2009 11:09 AM #7
Here is what worked - Thanks!
Here is what worked - Thanks!
I thought I'd just post what worked for me...
astypeStore =new Ext.data.Store({
reader: new Ext.data.JsonReader({
root:'astype'
},['astype'
])
});
// Define Shapes Datastore
// Airport data store
shapeStore =new Ext.data.Store({
url: myUrl,
reader: new Ext.data.JsonReader({
root:'schedshp'
},['type',
'airspace_name',
'start_time',
'end_time',
'style',
'geom'
])});
shapeStore.on('load', function(ds){
astypeStore.loadData(shapeStore.reader.jsonData);
....
}
Using that code, I wound up with:
1) One server call - the myURL in the shapeStore
2) Two datastores
3) Each datastore using its own root element
Thanks for your support,
Jim
-
10 Dec 2009 3:44 PM #8
If anyone needs a more succinct example, this is what I used to make this work:
Hope that helps someone out there.PHP Code:var store1 = new Ext.data.Store({
url: '/path/to/json-data.php',
method: 'POST',
autoLoad: true,
reader: new Ext.data.JsonReader({
root: 'root1',
fields: ['field1', 'field2', 'field3']
}),
listeners: {
'load': function() {
store2.loadData(store1.reader.jsonData);
}
}
});
var store2 = new Ext.data.Store({
reader: new Ext.data.JsonReader({
root: 'root2',
fields: ['field1', 'field2', 'field3']
})
});
- Clint Nelissen
-
30 Aug 2010 12:36 AM #9
-
18 Mar 2012 7:11 PM #10
I can't call the reader.jsonData with extjs 4.0 framework.
what can i try to replace this method ?
Thanks.


Reply With Quote