Javascript jsTree:每次我删除一个节点时都会得到新的树JSON
我正在使用jsTree创建两个内容表(A和B),我将节点从A移动到B,每次我在树B中删除一个节点时,我都希望得到树B的json以将其保存在数据库中,但当我在drop事件中得到json时,它只得到json,而没有新节点 我需要得到包含新节点的树。我在事件“dnd_stop.vakata”中获得json,代码如下:Javascript jsTree:每次我删除一个节点时都会得到新的树JSON,javascript,jquery,html,jstree,jstree-dnd,Javascript,Jquery,Html,Jstree,Jstree Dnd,我正在使用jsTree创建两个内容表(A和B),我将节点从A移动到B,每次我在树B中删除一个节点时,我都希望得到树B的json以将其保存在数据库中,但当我在drop事件中得到json时,它只得到json,而没有新节点 我需要得到包含新节点的树。我在事件“dnd_stop.vakata”中获得json,代码如下: $(document).on('dnd_stop.vakata', function (e, data) { var json = $("#JSTreeTOC").jstree(
$(document).on('dnd_stop.vakata', function (e, data) {
var json = $("#JSTreeTOC").jstree(true).get_json();
console.log(JSON.stringify(json));
// Here I want to make an AJAX call to save the tree in database
});
另外,这是我创建jstree的代码:
//jsTree "A":
$('#JSTreeServicios').jstree({
'core': {
"check_callback": false,
'data': tree
},
"dnd": {
"always_copy": true,
},
"plugins": ["dnd", "search", "types", "contextmenu", "sort"]
});
//jsTree "B":
$('#JSTreeTOC').jstree({
'core': {
"check_callback": true,
'data': tree
},
"plugins": ["dnd", "search", "types", "sort", "contextmenu"]
});
一段时间后,我意识到在“dnd_stop.vakata”事件运行时jsTree没有被更新,几毫秒后发生了这种情况,为了解决localhost上的问题,我添加了以下行:
$(document).on('dnd_stop.vakata', function (e, data) {
setTimeout(function(){
var json = $("#JSTreeTOC").jstree(true).get_json();
console.log(JSON.stringify(json));
// Here I make an AJAX call to save the tree in database
}, 100);
});
我正在更新JSON好的,这里-@NikolayErmakov我看到了你的代码,我看不到你在哪里得到更新的JSON。对不起,没有保存更改。检查树下的灰色分区