View Full Version : how to add elememnts in Treeloader using java script

23 Mar 2010, 8:50 PM
Hello All,

Iam new to extjs.

Here my requirement is to get a tree , with a specified values in it .

I have a predefined data in json format , and using Treeloader(dataUrl:'mytest.js')

here mytest.js is the javascript which will echo the json object

the javascript code is like below

var type = [{id: 1,text: 'A leaf Node',leaf: true},{id: 2,text: 'A folder Node',children: [{id: 3,text: 'A child Node',leaf: true}]}];

return type;

i call initialize the treeloader as below

loader: new Tree.TreeLoader({dataUrl:'obj.js'}),^M

i want to give that data to Treeloader from the above java script.

If i remove the variable type and return it directly takes and get the output as i desired , but i want to pass the json object from javascript file (similar to the get-nodes.php by default instead of php here i want to get from java script ) here instead of return i even tried echo but no use.

6 Apr 2010, 7:12 AM
Try this:

var treePanel = new Ext.tree.TreePanel({
id: 'tree-panel'
,title: 'Navigation'
,height: 300
,minSize: 150
,autoScroll: true
,rootVisible: false
,lines: false
,useArrows: true
text: 'rootnode'
,id: 'rootnode'
,children: treeData

Where "treeData" must be a variable containing your json.
You migh want to provide it through a simple file like treeData.js like this. (Of cause it must be loaded before)

var treeData = {...you-json-config...};