将节点从一个 jstree 移动到另一个 jstree 不起作用

unr*_*sed 1 javascript tree jquery jstree

假设我们有 2 个 jstree 实例。这里的n1, n2节点来自第一棵树,n3, n4节点来自第二棵树。我想在 n4 中移动/拖动 n2 节点。但似乎该move_node方法在不同树实例上移动节点时不会触发。

$('#A').jstree({
  "core" : {
    "check_callback" : true,
    "data" : [{"text":"Root 1","id":"n1"}, {"text":"Root 2","id":"n2"}]
    },
  plugins:['dnd'],
});
$('#B').jstree({
  "core" : {
    "check_callback" : true,
    "data" : [{"text":"Root 3","id":"n3"}, {"text":"Root 4","id":"n4"}]
    },
  plugins:['dnd'],
});

//setTimeout(function () {

var a = $('#A').on('move_node.jstree', function(e, data) {
  console.log('move success');
});

var b = $('#B').on('move_node.jstree', function(e, data) {
  console.log('move success');
});

//}, 500);
Run Code Online (Sandbox Code Playgroud)
<head>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.1/themes/default/style.min.css">
</head>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.1/jstree.min.js"></script>

<div id="A"></div>
<div id="B"></div>
Run Code Online (Sandbox Code Playgroud)

是否可以在不同的 jstree 实例中拖放节点?

这是小提琴

Abd*_*eeh 5

有一个小的修正。您需要在事件结束时使用 .jstree() 初始化 jsTree 实例并使用文档级别调用

请在代码中进行更改:

var a = $(document).on('dnd_stop.vakata', function(e, data){
  alert('move success');
}).jstree();
Run Code Online (Sandbox Code Playgroud)

这工作正常!!

完整的 jsfiddle:jsfiddle.net/thanseeh/o3buztex/14

var a = $(document).on('dnd_stop.vakata', function(e, data){
  alert('move success');
}).jstree();
Run Code Online (Sandbox Code Playgroud)
$('#A').jstree({
	"core" : {
		"check_callback" : true,
    "data" : [{"text":"Root 1","id":"n1"}, {"text":"Root 2","id":"n2"}]
	},
  plugins:['dnd'],
});
$('#B').jstree({
	"core" : {
		"check_callback" : true,
    "data" : [{"text":"Root 3","id":"n3"}, {"text":"Root 4","id":"n4"}]
	},
  plugins:['dnd'],
});

var a = $(document).on('dnd_stop.vakata', function(e, data){
 alert('move success');
}).jstree();
Run Code Online (Sandbox Code Playgroud)