1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
var jsTreeComponent = { init: function () { $.getJSON('/你后台获取树结构的api'), function (data) { if (data.success != true) { $jsTree.html('加载失败'); return; } else if (data.data.structureList.length == 0) { $jsTree.html('暂无数据'); return; } var structList = data.data.structureList;
var jsTreeBean = { id: "string", parent: "string", text: "string", icon: "glyphicon glyphicon-tag", state: { opened: true, disabled: false, selected: false }, li_attr: {}, a_attr: {} }; var jsTreeBeanList = [];
for (var i = 0; i < structList.length; i++) { var current = structList[i]; var newObj = Object.assign({}, jsTreeBean);
newObj.id = current.id; newObj.text = current.name; newObj.cusLevel = current.level; if (current.level == 0) { newObj.icon = 'glyphicon glyphicon-bookmark'; newObj.parent = '#'; } else { newObj.parent = current.parentId; }
jsTreeBeanList.push(newObj); }
$jsTree.jstree({ 'core': { 'check_callback': true, 'data': jsTreeBeanList } }); }); },
eventListener: function () { $jsTree.on("changed.jstree", function (e, data) { if (data.node.original.cusLevel == 1) { service.loadLearnResources(data.node.id) } }); } };
|