【问题标题】:Drag & Drop between two trees in jstree在 jstree 中的两棵树之间拖放
【发布时间】:2013-12-07 23:14:10
【问题描述】:

有 2 棵树。 Menu treeCategory tree,两个树中的一个节点可以在自己的树中移动(重新排序),Category树中的一个节点也可以移动(拖放) ) 到菜单树。 我绑定 move_node 的回调,每次在其树中拖放节点或将节点拖放到另一棵树时,都会执行此回调。我的代码:

// bind move node from one parnt to another event
.bind("move_node.jstree", function (e, data) {
    data.rslt.o.each(function (i) {
        $.ajax({
            async : false,
            type: 'POST',
            url: "/menus/move/",
            dataType: 'json',
            data : {
                "operation" : "move_node",
                "id" : $(this).attr("id").replace("node_",""),
                "parent" : data.rslt.cr === -1 ? 1 : data.rslt.np.attr("id").replace("node_",""),
                "oldParent" : data.rslt.op.attr("id").replace("node_",""),
                "position" : data.rslt.cp + i,
                "oldPosition" : data.rslt.cop,
                "title" : data.rslt.op.children("a").text()
            }           });
    });
})

我怎样才能检测到这个移动的节点是用于另一棵树还是用于同一棵树。

【问题讨论】:

    标签: javascript jstree drag-and-drop


    【解决方案1】:

    根据文档,move_node 回调函数中的data.rslt 是一个move 对象。

    在该对象中,otrt 属性(分别为源树实例和引用树实例)可用于检查节点是被丢弃在同一棵树中还是不同的树中:

    .bind("move_node.jstree", function (e, data) {
       if(data.rslt.ot != data.rslt.rt) {
          console.log("Node was moved to a different tree-instance");
       }
       else {
          console.log("Node was moved inside the same tree-instance");
       }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-04
      • 1970-01-01
      相关资源
      最近更新 更多