jsTree 通過ajax 獲取json資料 載入樹形選單
阿新 • • 發佈:2019-01-24
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" ] }); }