我正在使用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(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,它发生在几毫秒后,为了解决本地主机上的问题,我添加了以下几行:
$(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);
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句