Naj*_*bet 4 jquery drag-and-drop jstree
我开发了一个出现的确认警报
do you want to move this file or folder ?
如果我点击no:它返回默认文件夹.
如果yes它会转到新文件夹.
所以我的问题是当我拖放父文件夹时会出现确认消息,如果我点击no动作没有停止,那就意味着该文件夹将在新文件夹下移动
例如我有:
在我jstree我有 目录root1和根-2这是父节点所以,当我移动节点child1到根-2它工作正常.但当我将ROOT2移动到ROOT1时,它点击时并没有停止运动no
这是我的代码:
// html demo
$('#tree').jstree({
"core" : {
"animation" : 0,
"check_callback" : true,
"data" : [
{ "id" : "ajson1", "parent" : "#", "text" : "Simple root node" },
{ "id" : "ajson11", "parent" : "#", "text" : "Simple root 1 node" },
{ "id" : "ajson12", "parent" : "#", "text" : "Simple root 2 node" },
{ "id" : "ajson2", "parent" : "#", "text" : "Root node 2" },
{ "id" : "ajson3", "parent" : "ajson2", "text" : "Child 1","type" : "file" },
{ "id" : "ajson4", "parent" : "ajson2", "text" : "Child 2","type" : "file" },
]
},
"types" : {
"#" : {
"max_children" : 1,
"max_depth" : 4,
"valid_children" : ["root"]
},
"root" : {
"icon" : "/static/3.1.1/assets/images/tree_icon.png",
"valid_children" : ["default"]
},
"default" : {
"valid_children" : ["default","file"]
},
"file" : {
"icon" : "glyphicon glyphicon-file",
"valid_children" : []
}
},
"plugins" : [
"contextmenu", "dnd", "types"
]
});
var Parent = 0;
var newParent = 0;
var Pos = 0;
var newPos = 0;
$(document).on('dnd_start.vakata', function (event, data) {
sel = "li#"+ data.data.nodes[0] +".jstree-node";
Parent = $('#tree').jstree(true).get_node(data.data.nodes[0]).parent;
Pos = $(sel).index();
});
$(document).on('dnd_stop.vakata', function (event, data) {
node = data.data.origin.get_node(data.data.nodes[0]);
if (node.type == "root")
{
return false;
}
if (confirm("Voulez vous vraiment deplacer le fichier ou le dossier ?") === false)
{
$('#tree').jstree(true).move_node(node,Parent,Pos);
return false;
}
sel = "li#"+ data.data.nodes[0] +".jstree-node";
newPos = $(sel).index();
newParent = node.parent;
});
Run Code Online (Sandbox Code Playgroud)
和此是示例
不需要使用这些dnd_*事件,你最好使用这个check_callback功能:
"check_callback" : function (op, node, par, pos, more) {
if ((op === "move_node" || op === "copy_node") && node.type && node.type == "root") {
return false;
}
if ((op === "move_node" || op === "copy_node") && more && more.core && !confirm('Are you sure ...')) {
return false;
}
return true;
},
Run Code Online (Sandbox Code Playgroud)
这是您更新的演示:http://jsfiddle.net/bq8xme0y/6/
您也可以从设置dnd.is_draggable功能中受益- 防止某些节点被拖动(因为在我看来这是您需要的其他东西).