Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Leonard on Mar 12, 2008 04:49
open dhtmlx forum
access tree object by JSON, or JSArray

Hi,

I'm getting a problem when serializing the tree to JSON. It just gave me zero object.

This is my snippet:
    tree=new dhtmlXTreeObject("treeboxbox_tree","100%","100%",0);
    tree.setImagePath("images/");
    tree.enableHighlighting(1);
    tree.enableSingleRadioMode(true);
    tree.attachEvent("onClick",onNodeSelect);
    tree.enableKeyboardNavigation(true);
    tree.setChildCalcMode(true);
    tree.enableTreeLines(false);
    tree.enableMultiLineItems(true);
    tree.loadXML("fileCategories.xml");//load root level from xml
    tree.openAllItems(0);
    myDataProcessor = new dataProcessor("fileCategoriesCrudOutput.xml");
    myDataProcessor.init(tree);

I tried to put alert(tree.getAllFatItems()); at the end but it gave me null response. And I tried to output the tree.serializeTreeToJSON()
and it just gave me {id:'0', item:[]} output

I would like to be able to do an interation of all items on the tree so that I can change the text, html, etc...

Any help would be appreciated

TA

Answer posted by Support on Mar 12, 2008 08:55
Problem can't be reconstructed locally, please check attached sample, it loads data from XML, but serialize it back to JSON and all works correctly.

>>I tried to put alert(tree.getAllFatItems()); at the end
If you placing command directly after loadXML it will not work. Data loading is async, so you need to catch the moment when data ready. It can be done by using onXLE event or second parameter of loadXML

    tree.loadXML("fileCategories.xml",function(){
       alert(tree.serializeTreeToJSON());
    });
Attachments (1)