Refresh Branch

I need to refresh a branch of a tree. I’ve tried refreshItem, this creates a duplicate of the branch. I’ve tried smartRefreshitem, and smartRefreshBranch but nothing happens. I’m however able to refresh the entire tree.



This is my code for initiating the tree:

tree4=new dhtmlXTreeObject(document.getElementById(‘treeBox_4’),“100%”,“”,0);

tree4.setImagePath(“js/dhtmlxTree/codebase/imgs/csh_vista/”);

tree4.enableCheckBoxes(false);

tree4.setOnClickHandler(doOnClick4);

tree4.preventIECaching(true);

tree4.setXMLAutoLoading(“…”);

tree4.loadXML(“…”);

The code is correct and must not cause any problem.
Are you using refreshItem agains opened branch, or agains one, which never was loaded from server yet?
In second case problem with duplication may really occurs ( the XML will be loaded twice - one by refreshItem command, second automatically while opening item )

You can try to use next code snippet
if (tree.hasChildren(id) === true)
    tree.openItem(id);
else
    tree.refreshItem(id);

It will open item if it was never opened before, and will call refreshItem if item was already loaded.
Such approach must prevent duplication.

I’m always refreshing an open branch.

Well, refreshItem() actually works on branches, but it has the unwanted sideeffect that it duplicates the top-level items. I tried using smartRefreshItem but nothing seems to happen(?)

Both smartRefreshItem and smartRefreshBranch commands updated items in tree based on their IDs.
Please be sure that
    a) response XML has tree@id pointed to updated branch ID
    b) the item@id in response XML must be the same as IDs of items , which need to be updated