Problem with openOnItemAdded(false)

Hi,
I’m uisnig 3.0Pro and I’ve a weird behavior when using tree.openOnItemAdded(false).
Scenario: I’ve a dhtmlxtree that on startup loads a few nodes and then I want to manipulate them using JS. For example let’s say that at the beginning I’ve
R (Root Node)
→ A
and I want to obtain
R
→ A
→ B (Simply adding a node)

I tried this
var tree = new dhtmlXTreeObject(“treeBox”, “100%”, “100%”, “R”);
tree.openOnItemAdded(false);
tree.loadJSONObject({ id: “R”, open: true, item: [{ id: “A”, text: “A”, item: []}] });
tree.insertNewChild(“R”, “B”, “B”, 0, 0, 0, 0, null);
tree.openItem(“R”);
and only “A” node shows.

If I remove the tree.loadJSONObject, node “B” is showed correctly, but, obviously, node “A” is no more there.

If I remove tree.openOnItemAdded(false) everything works correctly.
I’ve debugged it a bit, and it is some problem with the status of your nodes.
For the moment I’ll remove the openOnItemAdded(dalse), but in future I’ll need it.
May you provide some help?

Best regards, Andrea Pirola

Hi,

tree.openOnItemAdded(false); should be called before child nodes are added. Please see the sample:

dhtmlxTree/samples/12_loading_processing_data/01_pro_add_item.html

Please see the function for “build closed tree”. The method is called after the top-level items are added.