Reputation: 1
say i have a json string like this: Code:
{"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!
Upvotes: 0
Views: 1198
Reputation: 71150
The basic rule is this:
Same underlying dataset but different columns need to be shown? using the same store is OK (simply point the combobox to the field requried).
Different underlying dataset (no relation between desired fields)? Different stores should be used.
Upvotes: 0
Reputation: 3253
You can have two different JsonReaders. Just switch between them manually (i.e. using events of comboboxes).
Upvotes: 0
Reputation: 62894
As others have said, you want one store per combobox.
If you have fairly static data, grab them as Json once, and stick it in some global array. The use simple ArrayStores for each combo, to avoid going back to the server all the time.
If the data are volatile, then you'll have to fetch them over and over, so you might as well just use two seperate JsonStores, with JsonReaders that hit the same script to server yer data.
Upvotes: 0
Reputation: 8376
A store will only have one set of records in it after a load operation; you won't get what you want from doing the above.
I would use two separate stores. One configured to load, say, students, and the other configured to load staff by using the loadData function using the json the first retrieved on receipt of the load event.
Upvotes: 0
Reputation: 21497
I'm not 100% on this but I'm pretty sure best practices is one store per combo box. If you have to make 20 small AJAX requests to make your form, you make 20 requests. It's really not that much data. In the long run it'll make your app easier to maintain because you won't have some super request that has all these unrelated bits of data from a bunch of combo boxes.
Upvotes: 1