1

I'm trying to copy all selected nodes from one fancytree control to another one on the same page. So far I've tried the following code but the second tree remains blank:

        var sourceTree= $("#tree").fancytree("getTree");
        var destinationTree= $("#destinationTree").fancytree("getTree");

        var selectedNodes = sourceTree.getSelectedNodes();
        var rootNode = destinationTree.rootNode;

        rootNode.addChildren(selectedNodes);

Any ideas?

Thanks

Dr. Greenthumb
  • 2,280
  • 5
  • 27
  • 33
  • Welcome to StackOverflow! Please see ["Should questions include “tags” in their titles?"](http://meta.stackexchange.com/questions/19190/should-questions-include-tags-in-their-titles), where the consensus is "no, they should not". –  Nov 20 '14 at 07:23

1 Answers1

4

addChildren expects a plain object, so you could try

$.each(sourceTree.getSelectedNodes(), function(idx, node){
    destinationTree.rootNode.addNode(node.toDict());
});

or

$.each(sourceTree.getSelectedNodes(), function(idx, node){
    node.copyTo(destinationTree.rootNode);
});
mar10
  • 14,320
  • 5
  • 39
  • 64