PDA

View Full Version : Question about TreeLoader



jin1212
28 Jun 2007, 2:04 PM
Hello,
I've been using prototype/scriptaculous with J2EE on the server side for a while now. Today I just discovered ext's treepanel, which is what I really need for my current project.
I included ext-prototype-adapter.js, ext-all.js, scriptaculous.js on my page

I tried to follow the example from demo:
function enableTree(){
var Tree = Ext.tree;

var tree = new Tree.TreePanel('tree-div', {
animate:true,
loader: new Tree.TreeLoader({dataUrl:'servlet?action=GetJsonTree'}),
enableDD:true,
containerScroll: true
});

tree.loader.on('load', function(){alert("load")}, this,true);
tree.loader.on('loadexception', function(){alert("load exception")}, this,true);

// set the root node
var root = new Tree.AsyncTreeNode({
text: 'Ext JS',
draggable:false,
id:'source'
});
tree.setRootNode(root);

// render the tree
tree.render();
root.expand();
}



From my servlet I write out this JSON string:
[{"text":"widgets","id":"source\/widgets", "leave":false}]


On the client side, I see the load, and loadexception alert, and I can only see Ext js as root and nothing else. I appreciated if I can get some guidance, as I am brand new to ext and JSON.

thank you, jin

tryanDLS
28 Jun 2007, 2:34 PM
If you're getting a loadexception, there's a problem with your data. Try setting a BP in the TreeLoader where it fires that and see what's wroing. Also shouldn't 'leave' be 'leaf', or is that a custom attr you're returning?

jin1212
28 Jun 2007, 3:09 PM
yeah, 'leave' should be 'leaf', but that still doesnt help.
I'm not sure where exactly where I should set the break point because ext-all.js is virtually unreadable..

I can see from firebug the response coming back is : [{"text":"widgets","id":"source\/widgets", "leaf":false}]
The content type is "text/html;charset=UTF-8"

tryanDLS
28 Jun 2007, 3:26 PM
Switch to ext-all-debug which is readable.