jstree阻止将节点移动到子节点

所以我现在已经使用jstree了一段时间,但仍然无法处理它,这几乎是一个令人头痛但很好,我们决定使用它。 我使用的数据来自HTML(不涉及JSON)。 我遇到的问题是,我不确定如何设置某些节点不是文件夹。 每个节点都有一个类,并且基于该类我可以更改它的图标但是如果用户试图在这些节点内发送任何不应该是文件夹的节点,他们就可以。 我需要以某种方式阻止这种情况,但到目前为止我测试的每件事都根本不起作用。

$("jstree").jstree({ "core": { "animation": 0, "check_callback": true }, rules: { draggable: "all" }, "dnd": { "drop_finish": function (data) { if (data.o.attr("rel") === "ds") { //update chart with new data here? //using data.o.attr("id") } }, "drag_check": function (data) { if (data.r.attr("rel") != "ds") { return false; } return { after: false, before: false, inside: true }; } }, "crrm": { "move": { "check_move": function (data) { // alert(data.r.attr("id")); if (data.r.attr("id") == "999") { return false; } else { return true; } } } }, "plugins": ["dnd", "crrm"] }); 

这就是我用来创建树的东西。 此外,我无法禁用拖放function,因为如果用户需要移动某些项目,但显然用户不应该将某些内容拖动到非文件夹的任何内容中。

在此先感谢您的帮助,

问候,

阿德里安。

我通过使用Types plugin jstree插件完成了这个。 在那里,您可以定义节点类型并设置valid_children变量,允许哪些类型为子节点。 这意味着用户也不能将受限类型的DnD节点放入节点。

在下面的示例中,我有一个类型“book”,可以将“folder”和“file”节点作为子节点。 “文件”类型根本不能包含任何子项,因为valid_children被定义为空。

  $('#' + tree_id) .jstree({ 'core' : { 'check_callback' : true, //needed to enable create, remove, rename... events "themes" : { "stripes" : true } }, "types" : { "book" : { "valid_children" : ["folder", "file"], "icon" : "img/1397762742_book.png" }, "folder" : { "valid_children" : ["folder", "file"], "icon" : "img/1397751666_folder.png" }, "file" : { "valid_children" : [], "icon" : "img/1397752227_page.png" } }, "contextmenu" : { "items" : customMenu }, "plugins" : ["sort", "dnd", "contextmenu", "types"] }); 

添加新节点时可以设置type属性

 tree.create_node("#", { "text" : "sample node", "type" : "file" }); 

或者使用set_type函数。 API