在js中:
function makeEasyTree(data){
if(!data)
return [];
var _newData = []; //最终返回结果
var _treeArray = {}; //记录一级节点
var _root = 0; //最顶层fid
var _idKey = "id"; //主键的键名
var _fidKey = "fid"; //父ID的键名
_getChildren(_root);
function _getChildren($root){
var $children = [];
for (var i in data){
if($root == data[i][_fidKey]){
data[i]["children"] = _getChildren(data[i][_idKey]);
$children.push(data[i]);
}
//只要一级节点
if(_root == data[i][_fidKey] && !_treeArray[data[i][_idKey]]){
_treeArray[data[i][_idKey]] = data[i];
_newData.push(data[i]);
}
}
return $children;
}
return _newData;
}
var menuData
var hh
$(function(){
menuData=[];
$.ajax({
type:"POST",
url:'power/allpower',
dataType: "json",
success:function(data){
for(var i in data){
hh={"id":data[i].id,
"fid":data[i].f_id,
"text":data[i].name,
"attributes":{ "url":data[i].url },
/*"nodeurl":data[i].url,*/
"state":"closed",
};
menuData.push(hh)
}
menuData = makeEasyTree(menuData);
$('#tt').tree({data:menuData,
})
$('#tt').tree("options").cascadeCheck=false
}
})
$('#tt').tree({
"checkbox":"true",
});
})
在jsp中:
<ul id="tt" class="easyui-tree" ></ul>
数据库:
控制层:
就是把数据库的内容通过ajax全部导入进来