| Issue 71: | Copy nodes/branches | |
| 1 person starred this issue and may be notified of changes. | Back to list |
What steps will reproduce the problem?
1. Created a dynatree:
$("#westScrollPane").dynatree({
persist: false,
clickFolderMode: 1, // 1:activate, 2:expand, 3:activate and expand
checkbox: false, // Show checkbox
onDblClick: function(dtnode) {
$("#echoActive").text("Double Click on: "+dtnode.data.title);
dtnode.toggleExpand();
},
onActivate: function(dtnode) {
$("#echoActive").text("(Level "+dtnode.getLevel()+")
"+dtnode.data.title);
},
onDeactivate: function(dtnode) {
$("#echoActive").text("-");
},
children: [ // Pass an array of nodes.
{
title: "Item 1"
},
{
title: "Folder 1",
isFolder: true,
children: [
{
title: "Folder 1.1",
isFolder: true,
},
{
title: "Sub-item 1.2"
}
]
},
{title:
"Folder 2",
isFolder: true,
children: [
{title: "Sub-item 2.1"},
{title: "Sub-item 2.2"}
]
}
]
});
2. Added a var to hold a "clipboard" node:
var treeClip = null;
3. Implemented a copy action (using a context menu):
function(action, el, pos) {
var key="_"+$(el).attr("id").split("_")[1];
var node1=$("#westScrollPane").dynatree("getTree").getNodeByKey(key);
.
.
.
if(action=="copy"){
treeClip=node1;
console.log("saving node to clipboard: "+treeClip);
};
4. Implemented a paste operation:
if(action=="paste_inside"){
console.log("pasting from clipboard: "+treeClip);
node1.append(treeClip);
};
What is the expected output? What do you see instead?
I was expecting to paste a copy of the node, but pasted a null node
instead. If I appenf treeClip.data, then I will create a top level node,
but no children.
What version of the product are you using?
$Version: 0.4.0_beta-1$
$Revision: 166, 2009-02-02 08:43:12$
On what operating system and browser?
Vista, Firefox 3.0.6
Please provide any additional information below.
Feb 11, 2009
#1
bob65423...@gmail.com
Feb 12, 2009
I think that I figured out that I need to append a node and then append its children. Now the problem is that node.data.children an node.childList get out of sync after an append operation. See attached file
Feb 14, 2009
This should work:
var tree = $("#tree").dynatree("getTree");
var node122 = tree.getNodeByKey("122");
var clipboard = node122.toDict(true);
var node11 = tree.getNodeByKey("11");
node11.append([clipboard]);
Note, that you should take care to avoid duplicate keys, by removing them from the
dict. Also the 'selected', 'active' flags should be fixed, if required.
This shouild be easier in the future: issue #74 , issue #77
I started issue #76 for the [] bug
Owner:
moo...@wwWendt.de
Feb 14, 2009
So for now this is the suggested way to copy the node1 branch to node2:
var clipboard = node1.toDict(true, function(dict){
dict.title = "Copy of " + dict.title;
delete dict.key; // prevent duplicate keys
});
node2.append(clipboard);
Summary:
Copy nodes/branches
Status: Fixed
Feb 14, 2009
Thanks for your help! The code in your comment 4 seems to work. I added code to fix duplicate key values. I still have a problem that node.data.children an node.childList get out of sync after an append operation (see comment 2), but perhaps I shouldn't worry, since copy/paste seems to work. See attached. The code in comment 5 does not work, but I assume that is because you have changes to make to the plug-in? Thanks again.
Feb 14, 2009
Thats right, the latest changes are currently only available from the trunk https://code.google.com/p/dynatree/source/browse/#svn/trunk/src The node.data.children attribute is solely used when initializing the tree. After that all children are sre maintained in node.childList. So it should be no problem if they are out of sync. I should even remove the data.children, to free up memory... However, if you experience any problems, please let me know. ~m
Jul 17, 2012
considered verified
Status:
Verified
|