多个 JsonReaders 读取 JsonStore 数据的不同部分
假设我有一个像这样的 json 字符串: 代码:
{"Staff":[{"id":1,"name":"John"},{"id":2,"name":"Mary"},{"id":3, "姓名":"桑德拉"}],"学生":[{"id":2,"姓名":"彼得"},{"id":3,"姓名":"卡尔"},{"id ":4,"name":"Hodges"}]}
(注意:如果您想查看格式更好的 json 字符串,请将其粘贴到 http://json.parser.online.fr/)
我有两个组合框 cmbStaff 和 cmbStudents。是否可以将两个 comobox 绑定到同一商店但具有不同的 jsonreader?即 cmbStaff 的数据读取器将读取根为“Staff”的字符串,而 cmbStudent 将读取根为“Students”的字符串?
这是为了节省商店制作的 AJAX 数量,并为每个组合框设置不同的商店(想象一下,如果我的表单有 20 个组合框!)。
有什么想法吗?如果您需要更多信息,请随时通知我,谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我不是 100% 相信这一点,但我很确定最佳实践是每个组合框一个商店。如果您必须发出 20 个小型 AJAX 请求来制作表单,那么您将发出 20 个请求。数据确实没有那么多。从长远来看,它将使您的应用程序更易于维护,因为您不会有一些超级请求,其中包含来自一堆组合框的所有这些不相关的数据位。
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.
加载操作后,存储中将仅包含一组记录;执行上述操作不会得到您想要的结果。
我会使用两个独立的商店。一个配置为加载学生,另一个配置为使用 loadData 函数使用收到加载事件时第一个检索到的 json。
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.
正如其他人所说,您希望每个组合框有一个商店。
如果您有相当静态的数据,请将它们作为 Json 获取一次,并将其粘贴到某个全局数组中。为每个组合使用简单的 ArrayStore,以避免一直返回服务器。
如果数据不稳定,那么您将不得不一遍又一遍地获取它们,因此您不妨使用两个单独的 JsonStore,并使用 JsonReaders 调用相同的脚本来服务器数据。
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.
您可以有两个不同的 JsonReader。只需手动在它们之间切换(即使用组合框的事件)。
You can have two different JsonReaders. Just switch between them manually (i.e. using events of comboboxes).
基本规则是这样的:
相同的基础数据集但需要显示不同的列?使用相同的商店就可以了(只需将组合框指向所需的字段)。
不同的基础数据集(所需字段之间没有关系)?应使用不同的商店。
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.