PDA

View Full Version : Help with getting an asyncTreeNode to display children



srp
20 Dec 2010, 8:07 AM
I'm having trouble getting an asyncTreeNode to display children. It's getting the data from a webservice, and I've checked that the webservice is returning data correctly and it appears to be. At least it looks like the same as what was detailed in the API doc for TreeLoader (http://dev.sencha.com/deploy/dev/docs/?class=Ext.tree.TreeLoader). I included my code below. I'm sure I'm just missing something obvious, but I can't seem to figure out what it is. The tree does show the root node correctly and if I expand it it makes the webservice call correctly and the data gets returned, but it never shows any children.

Any help would be appreciated.

JS code:


var rootNode = new Ext.tree.AsyncTreeNode({
expanded: false,
text: "root",
id: 1012456
});

var loader = new Ext.tree.TreeLoader({ dataUrl: "http://mypathtoservice"});
var tree = new Ext.tree.TreePanel({
useArrows: true,
autoScroll: true,
animate: true,
enableDD: false,
containerScroll: true,
border: false,
root: rootNode,
loader: loader
});

JSON result from webservice call

{"count":0,"status":0,"data":[{"id":1018138,"text":"Georgia","leaf":true},{"id":1018149,"text":"Florida","leaf":true},{"id":1018157,"text":"New Jersey","leaf":true},{"id":1018163,"text":"New York","leaf":true}],"type":"J"}

-Stephen

zachext
20 Dec 2010, 9:06 AM
For the tree loader, the response needs to be: "a JavaScript Array definition whose elements are node definition objects"

Your web service response should be something like this:


[
{"id":1018138,"text":"Georgia","leaf":true},
{"id":1018149,"text":"Florida","leaf":true},
{"id":1018157,"text":"New Jersey","leaf":true},
{"id":1018163,"text":"New York","leaf":true}
]

srp
20 Dec 2010, 12:23 PM
Thanks, I hadn't realized that we had an internal webservice that was intercepting the calls and doing some work on the backend. I did have another question though. I'm not able to get the loader to pass the parameters as JSON. Instead it passes it as "application/x-www-form-urlencoded". I tried to set it using different values for method, but it doesn't seem to work. Is there a way to pass it via JSON instead of as application/x-www-form-urlencoded?

Thanks.

-Stephen