The key code is as follows:
Store:
- VaRDS =NewExt. Data. Store ({
- Proxy:NewExt. Data. dwrproxy ({
- Callback: folder. getmessagelist,
- Params :{
- Start: '0 ',
- Limit: page_size
- }
- }),
- // Proxy: New Ext. Data. memoryproxy (messagelist ),
- Reader:NewExt. Data. objectreader ({
- Root: 'messages ',
- Totalproperty: 'Total' // used to analyze the total number of pages of the pagingtoolbar component of ext
- },[{
- Name: 'messageid'
- },{
- Name: 'from'
- },{
- Name: 'subobject'
- },{
- Name: 'sendtime'
- },{
- Name: 'contenttext'
- }])
- });
- // 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
- DS. On ('beforeload ',Function(){
- Ext. Apply (This. Baseparams ,{
- Folderid: currentfolderid
- });
- });
- DS. Load ({
- Params :{
- Start: currentstart,
- Limit: Currentlimit
- }
- }); // Specifies the start position and number
Custom dwrproxy and objectreader:
- Ext. Data. dwrproxy =Function(Config ){
- Ext. Data. dwrproxy. superclass. constructor. Call (This);
- Ext. Apply (This, Config |
- {});
- };
- 7ext. Extend (ext. Data. dwrproxy, ext. Data. dataproxy ,{
- // DWR request
- Load:Function(Params, reader, callback, scope, ARG ){
- Currentstart = Params. Start; // Save the start position of the current page record
- Currentlimit = Params. limit; // number of records saved on the current page
- Document. DWR = {
- Params: Params,
- Reader: reader,
- Callback: callback,
- Scope: scope,
- Arg: Arg
- };
- // Process Request Parameters and convert each request parameter to an array
- VaRCallparams =NewArray ();
- Callparams. Push (Params. folderid); // ID of the current folder
- Callparams. Push (Params. Start); // the start position of the request.
- Callparams. Push (Params. Limit); // number of requests
- If(This. Params! = Undefined &&This. Params! =Null){
- This. Callback. Call (This, Callparams,This. Loadresponse); // DWR request
- }
- Else{
- This. Callback. Call (This,This. Loadresponse );
- }
- },
- // Process the DWR response
- Loadresponse:Function(Response ){
- VaRDWR = Document. DWR;
- Try{
- // Ie throws an exception 'error: typeerror, object does not support this operation'
- // So use trycatch to suppress this exception
- DeleteDocument. DWR; // IE does not support Delete
- }
- Catch(E ){
- }
- VaRResult;
- Try{
- Result = DWR. Reader. Read (response); // read the JSON returned by the request
- }
- Catch(E ){
- // This. fireevent ("loadexception", this, DWR, response, e );
- DWR. Callback. Call (DWR. Scope,Null, DWR. ARG,False);
- Return;
- }
- DWR. Callback. Call (DWR. Scope, result, DWR. ARG,True);
- },
- Failure:Function(Errorstring, exception ){
- Console. Log ("DWR" + exception );
- },
- Update:Function(Params, records ){
- }
- });
- // Customize a reader for processing the returned message list
- Ext. Data. objectreader =Function(Meta, recordtype ){
- Ext. Data. objectreader. superclass. constructor. Call (This, Meta, recordtype );
- };
- Ext. Extend (ext. Data. objectreader, ext. Data. datareader ,{
- // Process the DWR response
- Read:Function(Response ){
- VaRResponsedecode = ext. util. JSON. Decode (response); // note that the JSON string generated by Java JSON-lib needs to be decoded.
- VaRData = responsedecode. messages;
- VaRSID =This. Meta?This. Meta. ID:Null;
- VaRRecordtype =This. Recordtype, fields = recordtype. Prototype. fields;
- VaRRecords = [];
- VaRRoot = data;
- For(VaRI = 0; I <root. length; I ++ ){
- VaROBJ = root [I];
- VaRValues = {};
- VaRId = OBJ [Sid];
- For(VaRJ = 0, jlen = Fields. length; j <jlen; j ++ ){
- VaRF = Fields. items [J];
- VaRK = (F. Mapping! = Undefined & F. Mapping! =Null)? F. Mapping: f. Name;
- VaRV =Null;
- VaRIdx = K. indexof (".");
- If(Idx =-1 ){
- V = OBJ [k]! = Undefined? OBJ [k]: f. defaultvalue;
- }
- Else{
- VaRK1 = K. substr (0, idx );
- VaRK2 = K. substr (idx + 1 );
- If(OBJ [k1] = undefined ){
- V = f. defaultvalue;
- }
- Else{
- VaRObj2 = OBJ [k1];
- V = obj2 [k2]! = Undefined? Obj2 [k2]: f. defaultvalue;
- }
- }
- V = f. Convert (v );
- Values [F. Name] = V;
- }
- VaRRecord =NewRecordtype (values, ID );
- Records [records. Length] = record;
- }
- Return{
- Records: records, // list of returned messages
- Totalrecords: responsedecode. Total // total number
- };
- }
- });