- 利用回调来处理服务器返回的数据, 默认只能解析固定格式的返回值
<div class="">
<div id="div-jstree">
<div id="jstree">
</div>
</div>
</div>
<script>
let jstree_ele = $("#jstree");
jstree_ele.jstree({
core: {
check_callback: true,
data: function (node, callback) {
$.ajax({
url: "/order-category/tree",
dataType: "json",
type: "POST",
data: {"id": node.id === '#' ? 0 : node.id},
success: function (data) {
let res = [];
if (isDataSuccess(data)) {
data = data.data;
for (let i = 0; i < data.length; i++) {
res.push({});
res[i].id = data[i].id;
res[i].text = data[i].name;
res[i].children = data[i].right - data[i].left > 1;
res[i].a_attr = {title: data[i].description};
res[i].icon = 'fa fa-bolt'
}
}
callback.call(this, res);
}
})
},
},
});
</script>