【问题标题】:Getting elemens id of a jstree on drag and drop在拖放时获取 jstree 的元素 id
【发布时间】:2014-01-10 13:23:18
【问题描述】:

我有 2 个 jstree,现在我正在尝试在它们之间实现拖放选项,但我似乎无法获得我正在拖动的元素的 id 或新父级的 id(拖放后)。 到目前为止,这是我创建的代码,但在我提醒的数据中没有任何 ID 或任何其他对我有帮助的信息。

$("#tree").jstree({


   "dnd" : {

        "drop_finish" : function(data) {
            alert(data.toSource());
        }
       },
   "plugins" : [ "themes", "html_data", "dnd", "ui", "types" ],
});

我还创建了一个可用的 Fiddle,其中包含 2 棵树和几乎所有我的代码。

如果有人能给我一个提示或想法,我将如何解决这个问题,我将不胜感激。

【问题讨论】:

    标签: javascript jquery drag-and-drop jstree


    【解决方案1】:

    试试这个

    $("#tree").bind('move_node.jstree', function(e, data) {
        alert(data.node.id);
        alert(data.parent);
        alert(data.old_parent);
        alert(data.position);
    }
    

    这些变量几乎是不言自明的。

    【讨论】:

      【解决方案2】:

      不要用“dnd”,像这样试试“crrm”吧。

      "crrm": {
              "move": {
                  "always_copy": "multitree",//create a copy node,prevent removing node
                  check_move: function(m) {
                      // use m.ot,m.rt to get the id of the node you are dragging or the node you will drop down.
                  }
                  ,"default_position": "last"
              }
          },
      

      请先阅读 jstree 文档。我花了更多时间来学习它。所以试着阅读文档,你想要的都在里面。

      【讨论】:

        【解决方案3】:

        你可以用这个,

        "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;
        },
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2012-11-06
          • 2013-05-12
          • 1970-01-01
          • 2014-11-30
          • 1970-01-01
          • 2013-04-28
          • 1970-01-01
          相关资源
          最近更新 更多