phphe / vue-draggable-nested-tree

Vue2 draggable tree component
https://hetree.phphe.com/
MIT License
345 stars 61 forks source link

Preventing drop for certain tree nodes #89

Open dini-m opened 5 years ago

dini-m commented 5 years ago

Hello phphe,

I am trying to limit the dropping of certain tree nodes underneath certain other tree nodes. Now I have different text in the data array and want to forbid that a tree node with the text 'A' from being child of a tree node with text 'B', even though they are droppable. Which position is the best to place this limitation? I tried putting the code in autoMoveDragPlaceHolder, in append and append Prev, and also in the function insertDplhAfterTo, but it doesn't work properly. It would be great if you could tell me what the append, prepend and the likes actually do.

Thanks in advance.

phphe commented 5 years ago
ondragend: {type: Function}, // hook. return false to prevent drop. arguments(node, draggableHelperInfo)
node._vm.store.dplh // placeholder
node._vm.store.dplh.parent
node._vm.store.dplh.parent.text
node.text
dini-m commented 5 years ago

I see. But how do I get the info of the target node, underneath of which another node is to be placed at? I don't see any variable called targetNode in the node. I want to forbid dropping underneath of a node, not as a child node.

phphe commented 5 years ago

the placeholder will be replaced after drop, so think placeholder(dplh) as target node.

dini-m commented 5 years ago

I mean, I need to get the information of the previousSibling, if I I were to drop a node at a new location. dplh is just the placeholder and doesn't contain any information about the text of the previous node.

phphe commented 5 years ago
// previousSibling
index = dplh.parent.children.indexOf(dplh)
dplh.parent.children[index-1] 
dini-m commented 5 years ago

Oh I did the same thing. Thanks for your help!

dini-m commented 5 years ago

Oh one other question. Is it possible to prevent dropping of a tree node from another tree underneath a certain tree node ? Because the ondragend function is only called when the dragged tree node comes from the same tree. If it comes come from another tree, only ondrop function is called. Returning false here does not forbid dropping. And my trees need to crossTree.

dini-m commented 5 years ago

oh don't mind that question earlier. I have solved the problem.