PDA

View Full Version : Ext.data.Store?????loadexception????



Mari
15 Jul 2009, 5:18 AM
?????????

????????????????????
?Ext.data.Store?loadexception???exception?????????????????????????
???timeout??????????????????????????
?Ext.data.Store?load????????????????????Connection???????????????Connection??????????????????????????

?????
??????????????onReady???Ext.data.Store?????Ext.grid.GridPanel ?????????????

?????????????????loadexception?????????????????????????????
???loadexception???????????????????????????????????????????????????

??????????????loadexception?????????????????????loadexception????????????????????????????

????????????????????????????????????????????????????????????????

???????????

yuki
16 Jul 2009, 8:04 PM
API???????Ext.data.Store?loadexception???????????????Store???????proxy?loadexception??????????????????????

HttpProxy??????????????


loadexception : ( Object this, Object options, Object response, Error e )

?????????3???response???status??????????????????????????????????

?????????Store???????????????loadexception????????????????load??????????????????????

?????Ext JS 3.0??loadexception??????????deprecated??exception?????????????????2.x??????????????????:s

Mari
17 Jul 2009, 5:17 AM
???????????????????????
?????????????????????????

????????????????????Ext.data.HttpProxy????????????????????????????setTimeout????this??????????????????????????



/**
* Ext.data.HttpProxy load???loadResponse?? override
* Connection????????
* ?????response.status=-1(timeout),0(connectionError)
*/
Ext.override(Ext.data.HttpProxy,{
retryCount : 0,
lastOptions : null,
proxyOptions : function(params, reader, callback, scope, arg){
this.lastOptions = new Array(params, reader, callback, scope, arg);
},
load : function(params, reader, callback, scope, arg){
if(this.fireEvent("beforeload", this, params) !== false){
//????
if(this.retryCount == 0){
this.proxyOptions(params, reader, callback, scope, arg);
}
var o = {
params : params || {},
request: {
callback : callback,
scope : scope,
arg : arg
},
reader: reader,
callback : this.loadResponse,
scope: this
};
if(this.useAjax){
Ext.applyIf(o, this.conn);
if(this.activeRequest){
Ext.Ajax.abort(this.activeRequest);
}
this.activeRequest = Ext.Ajax.request(o);
}else{
this.conn.request(o);
}
}else{
callback.call(scope||this, null, arg, false);
}
},
loadResponse : function(o, success, response){
var lastopt = this.lastOptions;
delete this.activeRequest;
if(!success){
if(response.status==0){
// No Connection ????
if(this.retryCount < 5){
this.retryCount = this.retryCount +1;
setTimeout(function() {
this.load(lastopt[0],lastopt[1],lastopt[2],lastopt[3],lastopt[4]);
},200);
return;
}else{
// ??????
this.retryCount=0;//???????? ???
this.fireEvent("loadexception", this, o, response);
o.request.callback.call(o.request.scope, null, o.request.arg, false);
return;
}
}else{
// timeout???,???
this.retryCount=0;//???????? ???
this.fireEvent("loadexception", this, o, response);
o.request.callback.call(o.request.scope, null, o.request.arg, false);
return;
}
}
var result;
this.retryCount=0;//???????? ???
try {
result = o.reader.read(response);
}catch(e){
// response.status :200???
this.fireEvent("loadexception", this, o, response, e);
o.request.callback.call(o.request.scope, null, o.request.arg, false);
return;
}
this.fireEvent("load", this, o, o.request.arg);
o.request.callback.call(o.request.scope, result, o.request.arg, true);
}
});
???setTimeout???????????????????????????????
???????????

yuki
17 Jul 2009, 6:02 PM
setTimeout????


var that = this;

???????setTimeout????


that.load(...);

???????????????Ext??????????setTimeout??????Function????????defer?????????


this.load.defer(...);

??????????????????????Ext.util.DelayedTask????TaskRunner???????setTimeout?????????????????????????????

Mari
19 Jul 2009, 10:46 PM
???????????????
defer??????load??????????????
????????????


/**
* Ext.data.HttpProxy load???loadResponse?? override
* Connection????????
* ?????response.status=-1(timeout),0(connectionError)
*/
Ext.override(Ext.data.HttpProxy,{
retryCount : 0,
lastOptions : null,
proxyOptions : function(params, reader, callback, scope, arg){
this.lastOptions = new Array(params, reader, callback, scope, arg);
},
load : function(params, reader, callback, scope, arg){
if(this.fireEvent("beforeload", this, params) !== false){
//????
if(this.retryCount == 0){
this.proxyOptions(params, reader, callback, scope, arg);
}
var o = {
params : params || {},
request: {
callback : callback,
scope : scope,
arg : arg
},
reader: reader,
callback : this.loadResponse,
scope: this
};
if(this.useAjax){
Ext.applyIf(o, this.conn);
if(this.activeRequest){
Ext.Ajax.abort(this.activeRequest);
}
this.activeRequest = Ext.Ajax.request(o);
}else{
this.conn.request(o);
}
}else{
callback.call(scope||this, null, arg, false);
}
},
loadResponse : function(o, success, response){
var lastopt = this.lastOptions;
delete this.activeRequest;
if(!success){
if(response.status==0){
// No Connection ????
if(this.retryCount < 10){
this.retryCount = this.retryCount +1;
this.load.defer(500,this,lastopt,true); //500ms??10?????
return;
}else{
// ??????
this.retryCount=0;//???????? ???
this.fireEvent("loadexception", this, o, response);
o.request.callback.call(o.request.scope, null, o.request.arg, false);
return;
}
}else{
// timeout???,???
this.retryCount=0;//???????? ???
this.fireEvent("loadexception", this, o, response);
o.request.callback.call(o.request.scope, null, o.request.arg, false);
return;
}
}
var result;
this.retryCount=0;//???????? ???
try {
result = o.reader.read(response);
}catch(e){
// response.status :200
this.fireEvent("loadexception", this, o, response, e);
o.request.callback.call(o.request.scope, null, o.request.arg, false);
return;
}
this.fireEvent("load", this, o, o.request.arg);
o.request.callback.call(o.request.scope, result, o.request.arg, true);
}
});


??????????????????