jsTree ajax 获取json数据加载树

时间:2021-10-27 12:00:42

后台获取json格式数据。
直接上代码。 最后有一张官方ajax获取tree的说明。

     var ajaxTreeSample = function() {

$("#tree_4").jstree({
"core" : {
"themes" : {
"responsive": false
},
// so that create works
"check_callback" : true,
'data' : function (obj, callback) {
var jsonstr="[]";
var jsonarray = eval('('+jsonstr+')');
$.ajax({
type: "POST",
url:"/bms/wechat/wemenu/show.do",
dataType:"json",
async: false,
success:function(result) {
var arrays= result.data;
for(var i=0 ; i<arrays.length; i++){
var arr = {
"id":arrays[i].menuId,
"parent":arrays[i].parentId=="root"?"#":arrays[i].parentId,
"text":arrays[i].menuName
}
jsonarray.push(arr);
}
}

});
callback.call(this, jsonarray);
}
},
"types" : {
"default" : {
"icon" : "fa fa-folder icon-state-warning icon-lg"
},
"file" : {
"icon" : "fa fa-file icon-state-warning icon-lg"
}
},
"state" : { "key" : "demo3" },
"plugins" : [ "dnd", "state", "types" ]
});

}

jsTree ajax 获取json数据加载树