PDA

View Full Version : Extending TreeLoader problems using directFn



forumuser1080
11 Mar 2011, 7:53 AM
I am extending TreeLoader for two reasons, one I need to do something different in processReponse and I need to provide a directFn so that I can set the http header in my reqeust.



MyTreeLoader = Ext.extend(Ext.tree.TreeLoader, {
directFn: function(callback, node, scope) {
this.transId = Ext.Ajax.request({
method:'GET'
url: 'myurl/treedata',
success: MyTreeLoader.superclass.handleResponse,
failure: MyTreeLoader.superclass.handleFailure,
headers : {
'accept': 'application/json'
},
scope: this,
argument: {callback: callback, node: node, scope: scope}
});
},

processResponse: function(response) {
// do some custom stuff
}

});


I run into problems because the callback, node, and scope are not being set correctly when my directFn is called.

And on success when superclass.handleResponse is called the response object is empty.

I can see in fire bug the request was made and my json was returned.

What am I doing wrong.

steffenk
11 Mar 2011, 8:15 AM
directFn is done for ExtDirect, which has a different handling.

If you use a TreePanel you can simply overwrite the requestData method and do your own stuff


requestData : function(node, callback, scope){
if(this.fireEvent("beforeload", this, node, callback) !== false){
if(this.directFn){
var args = this.getParams(node);
args.push(this.processDirectResponse.createDelegate(this, [{callback: callback, node: node, scope: scope}], true));
this.directFn.apply(window, args);
}else{
this.transId = Ext.Ajax.request({
method:this.requestMethod,
url: this.dataUrl||this.url,
success: this.handleResponse,
failure: this.handleFailure,
scope: this,
argument: {callback: callback, node: node, scope: scope},
params: this.getParams(node)
});
}
}else{


this.runCallback(callback, scope || node, []);
}
},