JSTREE, exact move position
I want to show an explicit tooltip while drag-drop tree node inside treeview.
example: "Node 1 will be moved before/after/inside Node 2"
From move_node callback argument, we can get the position ("before/after/inside") but not from check_move callback (neither from prepare_move). Tooltip should be displayed while drag-droping, so move_node is too late.
开发者_如何学PythonThe same problem when drag-drop external object to treeview, the drag_check callback from dnd plugin has no information about the position (we just know the target node but not if it is before, after or inside). In that case, even for drag_finish callback we don't have the information.
Is there somebody who can help me solving this issue ?
I just tested this and its working fine for me on prepare_move ...
.bind("prepare_move.jstree",function(event, data) {
console.log("o : " + data.rslt.o.attr("id"));
console.log("r : " + data.rslt.r.attr("id"));
console.log("p : " + data.rslt.p);
})
this is what is logged
o : item_3
r : item_2
p : inside
I am using JSTree v1.0RC2
Here what I use to do it with jQuery plugin jDialog (or you can replace it with a simple jAlert function):
.bind("move_node.jstree", function (e, data) {
var id = data.rslt.o.attr("id").replace("node_","");
var name = data.inst.get_text(data.rslt.obj);
jConfirm('Moving node name:' + name, 'dialog title'), function(answer) {
if (answer == true){
$.post("/js_trees/"+ id,
{
"_method" : "put",
"operation" : "moving_my_node",
"id" : data.rslt.o.attr("id").replace("node_",""),
"ref" : data.rslt.np.attr("id").replace("node_",""),
"position" : data.rslt.cp,
"title" : data.rslt.name,
"copy" : data.rslt.cy ? 1 : 0
},
function (r) {
if(!r.status) {
$.jstree.rollback(data.rlbk);
} else {
$(data.rslt.oc).attr("id", "node_" + r.id);
if(data.rslt.cy && oc.children("UL").length) {
data.inst.refresh(data.rslt.oc);
}
}
}
);
}else{
$.jstree.rollback(data.rlbk);
}
});
})
精彩评论