简体   繁体   中英

Copy selected nodes to a new tree

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

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);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM