Load second tree on clik button

Hi,

I have a jsp in which, on page load, build a tree:

tree = new dhtmlXTreeObject(“treebox”, “100%”, “100%”, 0);
tree.setSkin(‘dhx_skyblue’);
tree.setImagePath(“dhtmlxtree/imgs/csh_bluebooks/”);
tree.enableCheckBoxes(1);
tree.enableThreeStateCheckboxes(true);
tree.setXMLAutoLoading(“TreeLoader”);
tree.setDataMode(“json”);
tree.loadJSON(“TreeLoader?id=0”);

When I click on a button, a function is invoked in order to load a new tree:

var tree_json2 = {id:0,item:[{id:1,text:“first”},{id:2, text:“middle”,child:“1”,im0:“book.gif”,item:[{id:“21”, text:“child”}]},{id:3,text:“last”}]};
tree.enableCheckBoxes(true);
tree.deleteChildItems(0);
tree.setDataMode(“json”);
tree.loadJSON(tree_json2);

but I obtain no result tree. Please can you investigate on it?

Best regards

Hi
Just pay attention on a 2th tree name:
var tree_json2 = {id:0,item:[{id:1,text:“first”},{id:2, text:“middle”,child:“1”,im0:“book.gif”,item:[{id:“21”, text:“child”}]},{id:3,text:“last”}]};
tree_json2.enableCheckBoxes(true);
tree_json2.deleteChildItems(0);
tree_json2.setDataMode(“json”);
tree_json2.loadJSON(tree_json2);

It must be tree_json2 in all tree2 structure.

Hi Darya.

I’m sorry if I was not precise, but I realized that there was also another error caused by the use of the method loadJSON rather than loadJSONObject.

Now I’ll show you all the code of the function that is invoked:

var tree;
function changeTree(){
var tree_json = tree.serializeTreeToJSON();

var tree_json1 = {};
tree_json1 = tree_json;

var tree_json2 = {};
tree_json2 = JSON.stringify(eval("(" + tree_json + ")"));		

var tree_json3 = {"id":"0","item":[{"id":"category|category0|","text":"category1","child":"1"},{"id":"category|category1|","text":"category2"},{"id":"category|category2|","text":"category3","child":"1"},{"id":"category|category3|","text":"category4"}]};

tree.destructor();

tree = new dhtmlXTreeObject("treebox", "100%", "100%", 0);
tree.setSkin('dhx_skyblue');
tree.setImagePath("dhtmlxtree/imgs/csh_bluebooks/");
tree.enableCheckBoxes(1);
tree.enableThreeStateCheckboxes(true);
tree.setXMLAutoLoading("TreeLoader");
tree.setDataMode("json");
tree.loadJSONObject(tree_json3);

}

If you try to invoke this function, it works fine when loadJSONObject() take tree_json3 as argument, but it doesn’t work if loadJSONObject() take tree_json (or tree_json1 or tree_json2) as argument.
I want also underline that the value of tree_json3 simply is the output of tree.serializeTreeToJSON().

Thanks

If you are using PRO edition, please, provide us demo on support@dhtmlx.com with a link to this topic.
If you have standard edition, attach a demo here
docs.dhtmlx.com/doku.php?id=othe … leted_demo

Hi,

I have solved with eval() method. It works fine:

function changeTree(){
var tree_json = tree.serializeTreeToJSON();
tree.deleteChildItems(0);
tree.loadJSONObject(eval("(" + tree_json + “)”));
}

Thank you for interest.

Seems to be the same problem like I have.
But the eval method don’t works for me.
http://forum.dhtmlx.com/viewtopic.php?f=3&t=33956