【发布时间】:2020-02-11 11:04:01
【问题描述】:
我正在使用JSTree,为此,我加载了数据,但在某些情况下,我需要使用另一个即将到达的数据库过滤器重新加载数据。但是如何将数据添加到JSTRee,它始终保留旧数据。
我在complete中尝试如下:
complete: function() { a $('#mytree').jstree(true).refresh();
但没有变化。
function loadTreeContent(bindTo)
{
$.ajax({
type: 'get',
url: bindTo,
dataType: 'json',
success: function(data) {
$('#mytree').jstree({
'core' : {
'data' : data
},
'checkbox' : {
"keep_selected_style" : false
},
"plugins" : [ 'checkbox', 'contextmenu', 'state'],
'checkbox': {
three_state : true,
whole_node : false,
tie_selection : false
},
'contextmenu': {
'items': function ($node) {
var tree = $('#mytree').jstree(true);
if($node.a_attr.type === 'test')
return getTestContextMenu($node, tree);
}
}
});
},
complete: function() {
// This function will be triggered always,
// when ajax request is completed, even it fails/returns other status code
console.log("complete");
},
error: function() {
// This will be triggered when ajax request fail.
console.log("Error");
}
});
};
【问题讨论】:
-
一种方法是销毁并重新初始化 jstree 或者您可以使用
redraw(true)。
标签: javascript jstree