I want to move subchild to child nodes but I don't want to move subchild to parent node. I can move the childnode to another parent node, but it cannot be a parent node. Is jqtree better or jstree better for binding the conditions.
var data = [
{
label: 'node1',
children: [
{ label: 'child1',
children: [
{ label: 'sub-child1' }
]
},
{ label: 'child2' }
]
},
{
label: 'node2',
children: [
{ label: 'child3' }
]
}
];
$(function() {
$('#tree1').tree({
data: data,
dragAndDrop: true,
/*onCanMove: function(node) {
if (! node.parent.parent) {
// Example: Cannot move root node
return false;
} else {
return true;
}
},*/
onCanMoveTo: function(moved_node, target_node, position) {
console.log(node);
if (target_node == moved_node.parent.parent) {
return (position == 'inside');
}
else {
return true;
}
}
});
});
$('#tree1').on("click",function() {
var node = $('#tree1').tree('getSelectedNode');
console.log(node.name);
});
I got the solution, if anyone is looking for a similar problem, this might help All I had to do is this
fiddle