View Full Version : Problems overriding TreeLoader processResponse

11 Mar 2011, 9:45 AM
Trying to override the processResponse method to parse the json I am getting back from the server. I am querying a server that is not mine and the json is coming back in a different structure.

rootFolder: {
title: 'root folder',
files [], // array of files in this folder
folders[] // array of folders contained in this folder, not each folder will have same format, files[], and folders[]

I am having problems as I cannot get my data to show up in the TreePanel. All I see is the spinning wait icon like it is still trying to load data.

Here is my current code so that you can see what I am trying to do. I simplified the code to avoid recursion for now (get something simple working first) and I just want to add all files to the root node.

MyTreeLoader = Ext.Extend(Ext.tree.TreeLoader, {
// node in processResponse should be the root node I create in my tree panel
// lets just modify its text and insert its children
processResponse: function(response, node, callback, scope) {
// I am getting the root folder back from my service
// it contains an array of files and an array of folders
// each folder also contains arrays of files and folders
var rootFolder = Ext.decode(reponse.responseText);
getChildren= function(folder) {
var children = [];
// Just deal with files in root folder for now, skip recursing on folders
for (var j = 0; j < folder.files.length; j++) {
var file = folder.files[j];
id: file.id,
text: file.title,
leaf: true
return children;

node.text = rootFolder.title;
node.children = getChildren(rootFolder);

MyTree = function() {
MyTree.superclass.constructor.call(this, {
id : 'tree-panel',
rootVisible: true,
root : new Ext.tree.AsyncTreeNode({
hidden: false, // do not hide root folder
expanded: true // set to true so that my tree loader's load will fire
loader: new MyTreeLoader({
preloadChildren: false, // set this to false because I am loading all children
url: 'myurl/tree',
requestMethod: 'GET'