2015-05-22 112 views
3

我developped出現 do you want to move this file or folder ?拖放Jstree確認

確認警報如果我點擊no:它返回到默認的文件夾。

if yes它將會轉到新文件夾。

所以我的問題是,當我拖放父文件夾出現確認信息,如果我點擊no動作並沒有停止,這意味着該文件夾下新建文件夾

移動。例如我有:

  • 目錄root1
    • 文件夾1
      • Child1
  • 根-2

在我jstree我有目錄root1,哪些是父節點 所以,當我移動child1到根-2正常工作根-2節點。但是當我移動到根-2它目錄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的例子

回答

6

無需使用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函數中受益 - 防止某些節點被拖拽(因爲在我看來,這是您需要的其他東西)。

+1

它的作品謝謝:)) –

+0

Greate,Thnaks :) –