PDA

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



jamiem
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.

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

http://i131.photobucket.com/albums/p286/TimeTrialAnimal/createNode.jpg

jamiem
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);
}
})
});

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

jamiem
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
});
},

Animal
28 Jun 2010, 2:02 AM
Well done!