我使用的是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");
}
});
};发布于 2020-02-11 19:46:05
尝试redraw而不是refresh
complete: function() { a $('#mytree').jstree(true).redraw(true);发布于 2021-01-18 13:07:44
尝试:
$(".jstree").jstree(true).refresh(true, true);如果你在jstree中使用state (选中和选中)插件,那么刷新方法就会变得复杂。refresh方法有两个参数
refresh(skip_loading, forget_state)默认情况下:
indicator
true状态,则不会重新应用该结果。因此,默认情况下,如果您不指定任何值,它将在刷新之前应用现有状态。所以,我的情况是我需要清理我以前的状态,然后我需要调用
$(".jstree").jstree(true).refresh(true, true);查看https://github.com/vakata/jstree/issues/2112#issuecomment-421551095和源代码:https://github.com/vakata/jstree/blob/master/src/jstree.js
https://stackoverflow.com/questions/60167433
复制相似问题