【问题标题】:Drag and Drop events in dnd plugin in jstree are not getting calledjstree中dnd插件中的拖放事件没有被调用
【发布时间】:2011-05-24 05:07:23
【问题描述】:

我们使用 jsTree 来表示文件和文件夹。文件和文件夹可以从其他文件夹移入和移出。

为此,我启用了拖放插件。可以拖放文件夹和文件,但不会调用拖放时调用的事件。

我需要在拖放时触发这些事件,因为我需要使用 Ajax 在后端更新拖放状态。

请帮忙

下面是代码。

<script type="text/javascript" class="source">

$(function() {

        $("#folderTree").jstree( {
        "dnd" : {
            "drop_finish" : function () { 
                alert("DROP"); 
            },
            "drag_check" : function (data) {
                if(data.r.attr("id") == "phtml_1") {
                    return false;
                }
                return { 
                    after : false, 
                    before : false, 
                    inside : true 
                };

                alert("hhh jjj kk ");
            },
            "drag_finish" : function () { 
                alert("DRAG OK"); 
            }
        },

        "plugins" : [ "core", "html_data", "themes", "ui","dnd"],

        "ui" : {
            "initially_select" : [ "phtml_1" ]
        },

        "core" : { "initially_open" : [ "phtml_1" ] },

        "themes" : {
                "theme" : "apple"
        },

        "types" : {
            "valid_children" : [ "root" ],
            "types" : {
                "root" : {
                    "icon" : { 
                        "image" : "../images/drive.png" 
                    },
                    "valid_children" : [ "folder" ],
                    "draggable" : false
                },
                "default" : {
                    "deletable" : false,
                    "renameable" : false
                },

                "folder" : {
                    "valid_children" : [ "file" ],
                    "max_children" : 3
                },
                "file" : {
                    // the following three rules basically do the same
                    "valid_children" : "none",
                    "max_children" : 0,
                    "max_depth" : 0,
                    "icon" : {
                        "image" : "../images/file.png"
                    }
                }

            }
        }



    });
});

为了调用拖放事件,我是否遗漏了什么或者我需要做些什么?

【问题讨论】:

    标签: javascript jstree


    【解决方案1】:

    检查此网址Issue with JSTree drag drop 使用 class="jstree-drop" 以及所有节点的 ID。它会起作用的。 例如:- 如果你使用json数据

    "plugins" : [ "core", "json_data", "themes", "ui","dnd"],
    {
        {id : "id1",rel : "folder",class:"jstree-drop"},
        data:"New folder2",
        state:"closed"
    }
    

    如果我们使用 html 数据,则将 class="jstree-drop" 添加到所有节点。 然后 "drop_finish" 事件会正常工作,但不是 drag_check,drag_finish。我尝试在 css 类中添加 jstree-drag。

    更新(2011 年 7 月 19 日一小时后):- 将 jstree-draggable css 类添加到所有元素拖动事件也可以正常工作 更多信息http://www.jstree.com/documentation/dnd

    【讨论】:

      【解决方案2】:

      如果你想在树中拖动节点,你应该使用CRRM plugin,而不是DND。 DND用于将节点拖到树外或树之间。

      【讨论】:

      • 感谢您的回复。使用 CRRM 插件可以在树内拖放节点吗?我不想有任何按钮来移动文件和文件夹。
      • 在这种情况下,您需要将它们一起使用。看看那个演示和代码jstree.com/documentation/dnd#demo2。
      【解决方案3】:

      选项dnd.drag_check、dnd.drag_finish、dnd.drop_finish 用于外来对象。要管理在一棵树内(或树之间)的移动,请使用crrm.move.check_move。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-15
        • 1970-01-01
        • 2023-04-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多