JStree:轨道拖拽掉在树上

发布于 2024-12-24 02:32:28 字数 2227 浏览 2 评论 0原文

我(尝试)使用 JStree 作为类别/子类别树。 这花了相当长的时间,但我设法使用从数据库检索的 JSON 数据创建一棵树(使用 PHP 查询和构建 JSON 对象)。

现在我希望能够跟踪拖拽和拖拽。删除操作。 即:将主类别 a 中的子类别 x 拖至主类别 b。 我需要记录这一点以在操作后更改数据库。 我想我需要“check_move”或“drop_finish”函数。 drop-finish 根本不起作用,该事件未触发。这似乎是因为我的节点没有 jstree-drop 类,但我似乎无法正确插入该类:它不起作用。

check_move 函数在传递其他子类别时将继续触发,因此会创建大量不需要的数据。

我的(测试)JSON 数据:

[
{
    "metadata": {
        "id": "1"
    },
    "data": "Geluid",
    "children": [
        {
            "data": "Speakers",
            "attr": {
                "href": ""
            },
            "metadata": {
                "id": "1"
            }
        },
        {
            "data": "Versterkers",
            "attr": {
                "href": ""
            },
            "metadata": {
                "id": "3"
            }
        }
    ]
},
{
    "metadata": {
        "id": "2"
    },
    "data": "Licht",
    "children": [
        {
            "data": "Parren",
            "attr": {
                "href": ""
            },
            "metadata": {
                "id": "2"
            }
        }
    ]
}
]

我的 JStree 代码:

$(function () {
  $("#Create").click(function () {
    $("#tree").jstree("create");
    });     
  $("#Rename").click(function () {
    $("#tree").jstree("rename");
  });
  $("#Remove").click(function () {
    $("#tree").jstree("remove");
    });


    $("#tree").jstree({
        "dnd" : {
          "drop_finish" : function (data) {
         alert ("Drag OK");
          //alert("Dragged: " + data.o.attr('id') + " to " + data.r.attr('id'));         
        }
      },
      "themes" : {
            "theme" : "classic",
            "dots" : true,
            "icons" : false
        },
      "json_data" : {
            "ajax" : {
                "url" : "get_category_tree.php"
            }
        },
        "plugins" : [ "themes", "json_data", "ui", "crrm", "checkbox", "dnd" ]
    })
    .bind("select_node.jstree", function (e, data) {
      var req = new ZaxasRequest();
      req.getContent("category_content.php?id=" + data.rslt.obj.data('id') +"", "category_content");
    })
});

基本上,我想获取 ID。不要担心主类别和子类别 ID 可能相同,我稍后会解决这个问题;) 任何人都可以指出我正确的方向吗?

I'm (trying to) using JStree for a categorie/subcategorie tree.
It took quite some time, but I managed to create a tree with JSON data I retrieve from a database (using PHP for quering and building the JSON objects).

Now I would like to be able to keep track of drag & drop actions.
I.e.: subcategorie x from maincategory a is dragged to maincategorie b.
I need to record this to change the database after the action.
I figured I would need either the 'check_move' or 'drop_finish' functions.
drop-finish doesn't work at all, the event is not triggered. This seems to be because my nodes do not have the jstree-drop class, but I can't seem to get the class correctly inserted: it won't work.

The check_move function will keep triggering when passing other subcategories and therefor creates an load of unwanted data.

My (test) JSON data:

[
{
    "metadata": {
        "id": "1"
    },
    "data": "Geluid",
    "children": [
        {
            "data": "Speakers",
            "attr": {
                "href": ""
            },
            "metadata": {
                "id": "1"
            }
        },
        {
            "data": "Versterkers",
            "attr": {
                "href": ""
            },
            "metadata": {
                "id": "3"
            }
        }
    ]
},
{
    "metadata": {
        "id": "2"
    },
    "data": "Licht",
    "children": [
        {
            "data": "Parren",
            "attr": {
                "href": ""
            },
            "metadata": {
                "id": "2"
            }
        }
    ]
}
]

My JStree code:

$(function () {
  $("#Create").click(function () {
    $("#tree").jstree("create");
    });     
  $("#Rename").click(function () {
    $("#tree").jstree("rename");
  });
  $("#Remove").click(function () {
    $("#tree").jstree("remove");
    });


    $("#tree").jstree({
        "dnd" : {
          "drop_finish" : function (data) {
         alert ("Drag OK");
          //alert("Dragged: " + data.o.attr('id') + " to " + data.r.attr('id'));         
        }
      },
      "themes" : {
            "theme" : "classic",
            "dots" : true,
            "icons" : false
        },
      "json_data" : {
            "ajax" : {
                "url" : "get_category_tree.php"
            }
        },
        "plugins" : [ "themes", "json_data", "ui", "crrm", "checkbox", "dnd" ]
    })
    .bind("select_node.jstree", function (e, data) {
      var req = new ZaxasRequest();
      req.getContent("category_content.php?id=" + data.rslt.obj.data('id') +"", "category_content");
    })
});

Basically, I would like to get the ID's. Don't bother about the fact the maincategory and subcategory id might be the same, I'll fix that problem later on ;)
Anyone can point me in the right direction?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一世旳自豪 2024-12-31 02:32:28

绑定移动事件并使用 CRRM 插件...
稍后我将发布一些代码示例..
JSTree CRRM

Bind to the move event and use CRRM plugin ...
I'll post some code example later..
JSTree CRRM

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文