EXT combines the key code of DWR (running successful dwrproxy)

Source: Internet
Author: User
The key code is as follows:

Store:

  1. VaRDS =NewExt. Data. Store ({
  2. Proxy:NewExt. Data. dwrproxy ({
  3. Callback: folder. getmessagelist,
  4. Params :{
  5. Start: '0 ',
  6. Limit: page_size
  7. }
  8. }),
  9. // Proxy: New Ext. Data. memoryproxy (messagelist ),
  10. Reader:NewExt. Data. objectreader ({
  11. Root: 'messages ',
  12. Totalproperty: 'Total' // used to analyze the total number of pages of the pagingtoolbar component of ext
  13. },[{
  14. Name: 'messageid'
  15. },{
  16. Name: 'from'
  17. },{
  18. Name: 'subobject'
  19. },{
  20. Name: 'sendtime'
  21. },{
  22. Name: 'contenttext'
  23. }])
  24. });
  25. // Before a DWR request, the current Folder Id is added to the Request Parameters by default. In this way, the request parameters in the DWR request are: folderid, start, limit
  26. DS. On ('beforeload ',Function(){
  27. Ext. Apply (This. Baseparams ,{
  28. Folderid: currentfolderid
  29. });
  30. });
  31. DS. Load ({
  32. Params :{
  33. Start: currentstart,
  34. Limit: Currentlimit
  35. }
  36. }); // Specifies the start position and number

Custom dwrproxy and objectreader:

  1. Ext. Data. dwrproxy =Function(Config ){
  2. Ext. Data. dwrproxy. superclass. constructor. Call (This);
  3. Ext. Apply (This, Config |
  4. {});
  5. };
  6. 7ext. Extend (ext. Data. dwrproxy, ext. Data. dataproxy ,{
  7. // DWR request
  8. Load:Function(Params, reader, callback, scope, ARG ){
  9. Currentstart = Params. Start; // Save the start position of the current page record
  10. Currentlimit = Params. limit; // number of records saved on the current page
  11. Document. DWR = {
  12. Params: Params,
  13. Reader: reader,
  14. Callback: callback,
  15. Scope: scope,
  16. Arg: Arg
  17. };
  18. // Process Request Parameters and convert each request parameter to an array
  19. VaRCallparams =NewArray ();
  20. Callparams. Push (Params. folderid); // ID of the current folder
  21. Callparams. Push (Params. Start); // the start position of the request.
  22. Callparams. Push (Params. Limit); // number of requests
  23. If(This. Params! = Undefined &&This. Params! =Null){
  24. This. Callback. Call (This, Callparams,This. Loadresponse); // DWR request
  25. }
  26. Else{
  27. This. Callback. Call (This,This. Loadresponse );
  28. }
  29. },
  30. // Process the DWR response
  31. Loadresponse:Function(Response ){
  32. VaRDWR = Document. DWR;
  33. Try{
  34. // Ie throws an exception 'error: typeerror, object does not support this operation'
  35. // So use trycatch to suppress this exception
  36. DeleteDocument. DWR; // IE does not support Delete
  37. }
  38. Catch(E ){
  39. }
  40. VaRResult;
  41. Try{
  42. Result = DWR. Reader. Read (response); // read the JSON returned by the request
  43. }
  44. Catch(E ){
  45. // This. fireevent ("loadexception", this, DWR, response, e );
  46. DWR. Callback. Call (DWR. Scope,Null, DWR. ARG,False);
  47. Return;
  48. }
  49. DWR. Callback. Call (DWR. Scope, result, DWR. ARG,True);
  50. },
  51. Failure:Function(Errorstring, exception ){
  52. Console. Log ("DWR" + exception );
  53. },
  54. Update:Function(Params, records ){
  55. }
  56. });
  57. // Customize a reader for processing the returned message list
  58. Ext. Data. objectreader =Function(Meta, recordtype ){
  59. Ext. Data. objectreader. superclass. constructor. Call (This, Meta, recordtype );
  60. };
  61. Ext. Extend (ext. Data. objectreader, ext. Data. datareader ,{
  62. // Process the DWR response
  63. Read:Function(Response ){
  64. VaRResponsedecode = ext. util. JSON. Decode (response); // note that the JSON string generated by Java JSON-lib needs to be decoded.
  65. VaRData = responsedecode. messages;
  66. VaRSID =This. Meta?This. Meta. ID:Null;
  67. VaRRecordtype =This. Recordtype, fields = recordtype. Prototype. fields;
  68. VaRRecords = [];
  69. VaRRoot = data;
  70. For(VaRI = 0; I <root. length; I ++ ){
  71. VaROBJ = root [I];
  72. VaRValues = {};
  73. VaRId = OBJ [Sid];
  74. For(VaRJ = 0, jlen = Fields. length; j <jlen; j ++ ){
  75. VaRF = Fields. items [J];
  76. VaRK = (F. Mapping! = Undefined & F. Mapping! =Null)? F. Mapping: f. Name;
  77. VaRV =Null;
  78. VaRIdx = K. indexof (".");
  79. If(Idx =-1 ){
  80. V = OBJ [k]! = Undefined? OBJ [k]: f. defaultvalue;
  81. }
  82. Else{
  83. VaRK1 = K. substr (0, idx );
  84. VaRK2 = K. substr (idx + 1 );
  85. If(OBJ [k1] = undefined ){
  86. V = f. defaultvalue;
  87. }
  88. Else{
  89. VaRObj2 = OBJ [k1];
  90. V = obj2 [k2]! = Undefined? Obj2 [k2]: f. defaultvalue;
  91. }
  92. }
  93. V = f. Convert (v );
  94. Values [F. Name] = V;
  95. }
  96. VaRRecord =NewRecordtype (values, ID );
  97. Records [records. Length] = record;
  98. }
  99. Return{
  100. Records: records, // list of returned messages
  101. Totalrecords: responsedecode. Total // total number
  102. };
  103. }
  104. });

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.