In my application I have two instances of fancytree side by side with different contents. tree1
cannot be modified in any way and only serves to have its nodes copied into tree2
via drag & drop (the dnd
extension).
在我的应用程序中,我有两个不同内容的fancytree实例。 tree1不能以任何方式修改,只能通过拖放(dnd扩展)将其节点复制到tree2中。
In the dragDrop:
event of tree2
I have something akin to:
在dragDrop:tree2事件中,我有类似于:
if(data.otherNode.tree === node.tree){
data.otherNode.moveTo(node, data.hitMode);
}
else{
data.otherNode.copyTo(node, data.hitMode);
}
The issue is that when I use copyTo()
the node's key is also copied, and if I copy the same node multiple times throughout tree2
I inevitably end up with duplicate keys. I know fancytree is able to auto-assign non-duplicate keys (for instance if the source json for your tree has no key value) but I have no idea how to do that in this situation.
问题是,当我使用copyTo()时,节点的密钥也被复制,如果我在整个tree2中多次复制同一个节点,我不可避免地会得到重复的密钥。我知道fancytree能够自动分配非重复键(例如,如果你的树的源json没有键值),但我不知道在这种情况下如何做到这一点。
1 个解决方案
#1
2
copyTo()
has a callback function that allows you to modify the new node. Try this:
copyTo()有一个回调函数,允许您修改新节点。试试这个:
if(data.otherNode.tree === node.tree){
data.otherNode.moveTo(node, data.hitMode);
}
else{
data.otherNode.copyTo(node, data.hitMode, function(n){
// Set your new key here!
n.key = <NEW_KEY>;
})
}
#1
2
copyTo()
has a callback function that allows you to modify the new node. Try this:
copyTo()有一个回调函数,允许您修改新节点。试试这个:
if(data.otherNode.tree === node.tree){
data.otherNode.moveTo(node, data.hitMode);
}
else{
data.otherNode.copyTo(node, data.hitMode, function(n){
// Set your new key here!
n.key = <NEW_KEY>;
})
}