PDA

View Full Version : Multiple JsonReaders reading different sections of JsonStore's data



el.nino
26 Nov 2010, 5:16 AM
hi guys,

say i have a json string like this:

{"Staff":[{"id":1,"name":"John"},{"id":2,"name":"Mary"},{"id":3,"name":"Sandra"}],"Students":[{"id":2,"name":"Peter"},{"id":3,"name":"Carl"},{"id":4,"name":"Hodges"}]} (Note: If you want to see a better formatted json string please paste it on http://json.parser.online.fr/)

And I have two comboboxes cmbStaff and cmbStudents. is it possible to bind both comoboxes to the same store but having different jsonreaders? i.e. cmbStaff's datareader would read the string with root: 'Staff' and cmbStudent will read the string with root 'Students'?

This is to save the amount of AJAX gets being made by the store and having a different store for every comboBox (imagine if my form had 20 comboboxes!:-?:(().

Any ideas? Feel free to inform me if you need any more information :) Thanks!

griffiti93
26 Nov 2010, 6:54 AM
The way I've handled this exact scenario before is to make a single AJAX request for all my data. Then setup a store per combobox pointing to the appropriate "root" location for each store. You'll save server requests. It's ok to have a store per combo. The current design of the JsonStore only supports 1 reader.

Condor
26 Nov 2010, 7:33 AM
store1.load({
callback: function(){
store2.loadData(store1.reader.jsonData);
store3.loadData(store1.reader.jsonData);
store4.loadData(store1.reader.jsonData);
store5.loadData(store1.reader.jsonData);
}
});

el.nino
26 Nov 2010, 9:13 AM
:D You guys are the best! Much appreciated