【发布时间】:2015-05-22 10:49:37
【问题描述】:
我开发了一个出现的确认警报
do you want to move this file or folder ?
如果我点击no:它会返回到默认文件夹。
如果yes 它将转到新文件夹。
所以我的问题是,当我拖放 父文件夹 时,会出现确认消息,如果我点击 no 移动没有停止,这意味着文件夹将移动到新文件夹下
例如我有:
- ROOT1
- 文件夹 1
- 孩子1
- 文件夹 1
- ROOT2
在我的 jstree 中,我有 Root1 和 Root2 节点,它们是父节点
因此,当我将 child1 移动到 Root2 时,它工作正常。但是当我将 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;
});
this 就是例子
【问题讨论】:
标签: jquery drag-and-drop jstree