EXT 的Ext.data.DWRProxy

dwrproxy.js

Ext.data.DWRProxy = function(dwrCall, pagingAndSort){
  Ext.data.DWRProxy.superclass.constructor.call(this);
  this.dwrCall = dwrCall;
  //this.args = args;
 this.pagingAndSort = (pagingAndSort!=undefined ? pagingAndSort : true);
};

Ext.extend(Ext.data.DWRProxy, Ext.data.DataProxy, {
  load : function(params, reader, callback, scope, arg) {
    if(this.fireEvent("beforeload", this, params) !== false) {
      var sort;
      if(params.sort && params.dir) sort = params.sort + ' ' + params.dir;
      else sort = '';
      var delegate = this.loadResponse.createDelegate(this, [reader, callback, scope, arg], 1);
      var callParams = new Array();
      if(arg.arg) {
        callParams = arg.arg.slice();
   }
   
   if(this.pagingAndSort) {
       callParams.push(params.start);
       callParams.push(params.limit);
       callParams.push(sort);
   }
   
      callParams.push(delegate);
      this.dwrCall.apply(this, callParams);
    } else {
      callback.call(scope || this, null, arg, false);
    }
  },

  loadResponse : function(listRange, reader, callback, scope, arg) {
    var result;
    try {
      result = reader.read(listRange);
    } catch(e) {
      this.fireEvent("loadexception", this, null, response, e);
      callback.call(scope, null, arg, false);
      return;
    }
    callback.call(scope, result, arg, true);
  },

  update : function(dataSet){},

  updateResponse : function(dataSet)
  {}
});

Ext.data.ListRangeReader = function(meta, recordType){
    Ext.data.ListRangeReader.superclass.constructor.call(this, meta, recordType);
    this.recordType = recordType;
};
Ext.extend(Ext.data.ListRangeReader, Ext.data.DataReader, {
  getJsonAccessor: function(){
      var re = /[\[\.]/;
      return function(expr) {
          try {
              return(re.test(expr))
                  ? new Function("obj", "return obj." + expr)
                  : function(obj){
                      return obj[expr];
                  };
          } catch(e){}
          return Ext.emptyFn;
      };
  }(),
 
 read : function(o){
  var recordType = this.recordType, fields = recordType.prototype.fields;

  //Generate extraction functions for the totalProperty, the root, the id, and for each field
  if (!this.ef) {
   if(this.meta.totalProperty) {
    this.getTotal = this.getJsonAccessor(this.meta.totalProperty);
   }
  
   if(this.meta.successProperty) {
    this.getSuccess = this.getJsonAccessor(this.meta.successProperty);
   }

   if (this.meta.id) {
    var g = this.getJsonAccessor(this.meta.id);
    this.getId = function(rec) {
     var r = g(rec);
     return (r === undefined || r === "") ? null : r;
    };
   } else {
    this.getId = function(){return null;};
   }
   this.ef = [];
   for(var i = 0; i < fields.length; i++){
    f = fields.items[i];
    var map = (f.mapping !== undefined && f.mapping !== null) ? f.mapping : f.name;
    this.ef[i] = this.getJsonAccessor(map);
   }
  }

    var records = [];
    var root = o.data, c = root.length, totalRecords = c, success = true;

    if(this.meta.totalProperty){
     var v = parseInt(this.getTotal(o), 10);
   if(!isNaN(v)){
    totalRecords = v;
   }
  }

  if(this.meta.successProperty){
   var v = this.getSuccess(o);
   if(v === false || v === 'false'){
    success = false;
   }
  }

  for(var i = 0; i < c; i++){
     var n = root[i];
      var values = {};
      var id = this.getId(n);
      for(var j = 0; j < fields.length; j++){
    f = fields.items[j];
        var v = this.ef[j](n);      
        values[f.name] = f.convert((v !== undefined) ? v : f.defaultValue);
      }
      var record = new recordType(values, id);
      records[i] = record;
    }

    return {
       success : success,
       records : records,
       totalRecords : totalRecords
    };
  }
});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值