我试了很多。在页面加载工作正常。
我想在DataTable行上点击重新加载JStree。从DataTable行获取Id并将其传递给JStree。每当我把JSTree放在一个函数中。它不在页面上呈现。我尝试了不同的方法。但没有成功。仅适用于页面加载。
数据表
$('#roles').on('click', 'tr', function () {
var id = table.row(this).id();
alert(id);
id = table.row(this).id();
$.ajax({
async: true,
type: "POST",
url: '/Home/GetData',
dataType: "json",
data: { roleId: id },
success: function (json) {
createJSTree(json);
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
});
JSTree
function createJSTree(jsondata) {
$('#app_tree').jstree({
'core': {
'data': jsondata
}
});
}
在页面加载
$('#app_tree').jstree({
'plugins': ["wholerow", "checkbox", "types"],
'core': {
"themes": {
"responsive": false
}
}
});
这在页面加载时工作正常
$('#app_tree').jstree({
'plugins': ["wholerow", "checkbox", "types"],
'core': {
'check_callback': true,
"themes": {
"responsive": false
},
'data': {
'type': "POST",
"url": function (node) {
return "/Home/GetData?roleId=acb31181-b364-4a57-8806-70f5fcb07d1f";
},
'contentType': "application/json"
}
}
});
您可能需要重新绘制JSTree以获取新数据。
请检查类似的堆栈here