View Full Version : Ext.tree.TreeLoader - Can you use different fields instead of id and text in json

26 Jun 2010, 5:15 PM
I am getting data back from a web service which I want to load into a Ext.tree.TreePanel but the field which represents the node 'id' is called 'category_id' and the field which represents the 'text' field is called 'name' in the json response.

Is there a way to configure what json field represents the id and text fields for use with TreeLoader, I have checked the API docs and can't see a way.

26 Jun 2010, 10:33 PM
You missed this:


28 Jun 2010, 1:33 AM
so would I do the following with category_id being the id and name being the text value?

new Ext.tree.TreePanel({
loader: new Ext.tree.TreeLoader([
url: dataUrl,
createNode: function(attr) {
if(attr.isConsolidation) {
attr.iconCls = 'x-consol',
attr.allowDrop = true,
attr.id = 'category_id',
attr.text = 'name';
return Ext.tree.TreeLoader.prototype.createNodel.call(this, attr);

28 Jun 2010, 1:46 AM
Come on! Think about it!

28 Jun 2010, 1:53 AM
I done the following instead;

createNode: function(obj){
return new Ext.tree.AsyncTreeNode({
id: obj.category_id,
text: obj.name

28 Jun 2010, 2:02 AM
Well done!