gpt4 book ai didi

jquery - 拖放Jstree确认

转载 作者:行者123 更新时间:2023-12-03 22:59:28 32 4
gpt4 key购买 nike

我开发了一个出现的确认警报 您要移动此文件或文件夹吗?

如果我点击:它返回到默认文件夹。

如果它将转到新文件夹。

所以我的问题是,当我拖放父文件夹时,会出现确认消息,如果我单击,移动不会停止,这意味着该文件夹将移动到新文件夹下

例如我有:

  • ROOT1
    • 文件夹1
      • child 1
  • ROOT2

在我的 jstree 中,我有 Root1Root2 节点,它们是父节点因此,当我将 child1 移动到 Root2 时,它工作正常。但是当我将 ROOT2 移动到 ROOT1 时,当我单击

时,它并没有停止移动

这是我的代码:

// 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就是例子

最佳答案

无需使用 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;
},

这是您更新的演示:http://jsfiddle.net/bq8xme0y/6/

您还可以从设置 dnd.is_draggable 中受益。功能 - 防止某些节点被拖动(在我看来,这是您需要的其他东西)。

关于jquery - 拖放Jstree确认,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30394771/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com