ExtJS's Reader

Source: Internet
Author: User

ExtJS's Reader

Reader: Mainly used for the proxy data agent to read the data according to different rules to parse, the analysis of good data saved to Modle

Structure diagram

Ext.data.reader.Reader the root class of the reader

Ext.data.reader.Json Json-Formatted reader

Ext.data.reader.Array Array Reader for extended JSON

EXT.DATA.READER.XML XML-Formatted reader

Writer

Structure diagram

Ext.data.writer.Writer

Ext.data.writer.Json objects are interpreted as Json to be uploaded to the background

EXT.DATA.WRITER.XML objects are interpreted as Xml in the form of uploading to the background

1. JSON reader

[JavaScript]View PlainCopy
  1. (function () {
  2. Ext.onready (function () {
  3. var userData = {
  4. //total:200,
  5. COUNT:250,
  6. user:{
  7. UserID:' 1 ',
  8. Name:' uspcat.com ',
  9. orders:[
  10. {ID:' 001 ', Name:' Pen '},
  11. {ID:' 002 ', Name:' book '}
  12. ]
  13. }
  14. };
  15. //define Model
  16. Ext.regmodel ("user", {
  17. fields:[
  18. {name:' UserID ', type:' string '},
  19. {name: 'name ', type:' string '}
  20. ],
  21. Hasmany: {model: ' order '} //Define a property with multiple order
  22. });
  23. Ext.regmodel ("order", {
  24. fields:[
  25. {name: 'ID ', type:' string '},
  26. {name: 'name ', type:' string '}
  27. ],
  28. Belongsto: {type: ' Belongsto ', Model: ' user '} //definition belongs to
  29. });
  30. var mproxy = ext.create ("Ext.data.proxy.Memory", {
  31. Model:' user ',
  32. Data:userdata,
  33. reader:{
  34. Type:' json ',
  35. Root:' user ',
  36. Implicitincludes:True, //cascading read
  37. Totalproperty:' count '
  38. //record: ' Info '//The data returned by the server may be very complex, and a record can be used to delete the useful data information in the model
  39. }
  40. });
  41. Mproxy.read (new Ext.data.Operation (),function (result) {
  42. var datas = result.resultSet.records;
  43. alert (result.resultSet.total); //Print Count
  44. Ext.Array.each (Datas,function (model) {
  45. Alert (Model.get (' name '));
  46. });
  47. var user = result.resultset.records[0]; //Get the first data used
  48. var orders = User.orders (); //Get to the Orders collection in the user
  49. Orders.each (function (order) { //Traverse orders collection
  50. Alert (Order.get (' name '));
  51. });
  52. });
  53. });
  54. })();

2. Array Reader

[JavaScript]View PlainCopy
  1. Ext.onready (function () {
  2. Ext.regmodel ("person", {
  3. fields:[
  4. ' name ',' age '
  5. {name: ' Name '},
  6. {name: ' Age '}
  7. ],
  8. Proxy: {
  9. Type:' Ajax ',
  10. URL:' person.jsp ',
  11. reader:{
  12. Type:' array '
  13. }
  14. }
  15. });
  16. var person =ext.modelmanager.getmodel (' person ');
  17. Person.load (1,{
  18. Success:function (model) {
  19. Alert (Model.get (' name '));
  20. }
  21. });
  22. });

person.jsp file:

<%

Response.getwriter (). Write ("[[' Yunfengcheng ', 26]]");

%>

3. XML-Formatted Reader

[JavaScript]View PlainCopy
  1. (function () {
  2. Ext.onready (function () {
  3. Ext.regmodel ("user", {
  4. fields:[
  5. {name:' name '},
  6. {name:' ID '}
  7. ],
  8. proxy:{
  9. Type:' Ajax ',
  10. URL:' users.xml ',
  11. reader:{
  12. Type:' xml ',
  13. Record:' user '
  14. }
  15. }
  16. });
  17. var user = Ext.ModelManager.getModel (' user ');
  18. User.load (1,{
  19. Success:function (model) {
  20. alert (model);
  21. Alert (Model.get (' id '));
  22. }
  23. });
  24. });
  25. })();

Users.xml file:

[HTML]View PlainCopy
  1. <users>
  2. <user>
  3. <name>uspcat.com</name>
  4. <ID>00101</ID>
  5. </User>
  6. </users>

4. Writer's JSON and XML

[JavaScript]View PlainCopy
  1. Ext.onready (function () {
  2. Ext.regmodel ("person", {
  3. fields:[
  4. ' name ',' age '
  5. ],
  6. Proxy: {
  7. Type:' Ajax ',
  8. URL:' person.jsp ',
  9. writer:{
  10. Type:' json ' //Submit data using JSON
  11. //type: ' xml '//submit data Using XML
  12. }
  13. }
  14. });
  15. Ext.ModelMgr.create ({
  16. Name:' Uspcat.con ',
  17. Age:1
  18. },' person '). Save ();
  19. });

When writing with JSON, the browser views the commit information as if it were submitted in JSON:

When writing with XML, the browser views the commit information as if it were submitted in XML:

Original link: 8159774

ExtJS's Reader

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.