点击一个按钮,我发送一些键来控制并使用json获取我的列表,我的列表中的数组充当我的jstree中的孩子,
$("#btnSearch").on("click", function () {
alert("I'm also here");
$.ajax({
type: "POST",
url: "/Claims/JSTree",
success: function (response) {
var clients = [];
var claimKeys = [];
$.each(response.ClientNames, function (i, item) {
clients.push(item);
});
alert(clients);
$.each(response.ClaimNumbers, function (i, item) {
claimKeys.push(item);
});
alert(claimKeys);
$('#FolderTree').jstree({
'core': {
'data': [
{
'text': 'Client',
'state': {
'opened': false,
'selected': false
},
'children': clients
},
{
'text': 'Claim key',
'state': {
'opened': false,
'selected': false
},
'children': claimKeys
},
]
},
"plugins": ["checkbox"]
});
}
});
});
});
第一次一切正常,第二次我传递一个不同的键我得到列表,它甚至显示警报中的值,但我的jstree仍然保留以前的值..除非我停止并重新启动调试,jstree不会变空。有没有办法在用儿童填充之前清空jstree?
答案 0 :(得分:3)
尝试使用此代码,该代码首先销毁实例:
...
var tmp = $('#FolderTree').jstree(true);
if(tmp) { tmp.destroy(); }
$('#FolderTree').jstree({ ...
还要确保使用的是最新的jsTree版本。