PDA

View Full Version : Bug in TreeLoader ?



marklar
3 Apr 2007, 2:32 PM
I have to use an ugly hack in order to get the tree loader to work correct doing an async load from a server which wants the node parameter.

Here is the root of the problem I am running into:

The Ext.tree.TreeLoader requestData function calls getParams:


var params = this.getParams(node);


The getParams function seems to always return a string as the last line is:


return buf.join(""); //string only right?


The Ajax request function seems to want a params object and does not take a string.

Note: I hard coded the below statement and it did pass the values into the agents query_string. When I hard coded a string it did not work. This is making me think the Ext.lib.Ajax.request function wants an object for params not a string (at least in field=value format).


params = {node2:'demo'}; //works
params = 'node2=demo'; //does not work



Here is the code I use to hack in a fix - please help


//--- fix for bug or incorrect usage :) of async tree
Ext.tree.TreeLoader.prototype.requestData = function(node, callback){
if(this.fireEvent("beforeload", this, node, callback) !== false){
var params = this.getParams(node);
var cb = {
success: this.handleResponse,
failure: this.handleFailure,
scope: this,
argument: {callback: callback, node: node}
};
if (typeof params == 'object'){
this.transId = Ext.lib.Ajax.request(this.requestMethod, this.dataUrl, cb, params);
} else {
this.transId = Ext.lib.Ajax.request(this.requestMethod , this.dataUrl + '&' + params, cb, params);
}
}else{


if(typeof callback == "function"){
callback();
}
}
}



If I need to provide more details or better examples, let me know.

Thanks for your help.

Joseph

jack.slocum
3 Apr 2007, 4:49 PM
Actually it's the opposite. lib.Ajax always expects a string. Are you using prototype by chance?

marklar
3 Apr 2007, 5:23 PM
Here is the code, pretty basic.


var Tree = Ext.tree;

var tree = new Tree.TreePanel('somelabel'), {
animate:true,
loader: new Tree.TreeLoader({baseParams: {viewname:'wvNodesByCategory2Lev'}, dataUrl:'get-viewtree?openagent'}),
enableDD:true,
containerScroll: true,
dropConfig: {appendOnly:true}
});

// add a tree sorter in folder mode
new Tree.TreeSorter(tree, {folderSort:true});

// set the root node //was
var root = new Tree.AsyncTreeNode({
text: 'Site Map',
draggable:false, // disable root node dragging
id:'sitemap'
});
tree.setRootNode(root);

// render the tree
tree.render();

root.expand(false, /*no anim*/ false);

tree.on('click', this.nodeClicked );



Note: I am not using prototype to override the Ext.lib.Ajax.request functionality, this is very odd. But the test results I am seeing and the fact that it crashes without the above fix are really happening. I'll do more testing and see if I can come up with a simple way to recreate and will post anything I find in the way of funny string format or the like.

Also - Just a note - I tried this using the last Alpha and the latest Beta - the same result.

mpgupta
17 Oct 2007, 10:25 PM
new Ext.tree.TreeLoader({
baseParams :{a : 'aaa', b:'bbb'},
dataUrl:'dyntree.servlet'
});
And on server side, you can retrieve the value of "a" and "b".

Jack, this API can be extended like :


new Ext.tree.TreeLoader({
baseParams :[{a : 'aaa'}, {b:'bbb'}],
dataUrl:'dyntree.servlet'
});