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);
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().