treeData编辑形式:
treeData=[{
text : "一级标题",
children : [{
text : "二级标题",
children : [{
text : "二级标题",
attributes : {
url : ''
}
}
]
}
}];
js:
<script type="text/javascript">
$(function(){
loadMenu();
});
function loadMenu(){
$.ajax({
url: '<%=request.getContextPath()%>'+"/menu/getUserMenu",
dataType : "json",
type: "post",
data:{
time:new Date()
},
timeout: 8000,
success: function(data){
var str="<ul class='easyui-tree'>";
var menuList=data.menuList;
var treeData=new Array();
var treeObject={
text:"",
children:new Array()
}
var treeChidrenObject={
text:"",
attributes:{
url:""
}
}
for(var i=0;i<menuList.length;i++){
treeObject={
text:"",
children:new Array()
}
treeObject.text=menuList[i].title;
var list=menuList[i].list;
for(var j=0;j<list.length;j++){
treeChidrenObject={
text:"",
attributes:{
url:""
}
}
treeChidrenObject.text=list[j].title;
treeChidrenObject.attributes.url=list[j].url;
treeObject.children.push(treeChidrenObject);
}
treeData.push(treeObject);
}
console.log(treeData);
$("#nav").tree({
data : treeData,
lines : true,
onClick : function (node) {
if (node.attributes) {
addTab(node.text, node.attributes.url);
}
}
});
},
error: function() {
alert("异常!");
}
});
}
</script>
<div>
<ul id="nav">
</ul>
</div>
菜单:center js:
<script type="text/javascript">
function addTab(title, url){
/* if ($('#centerTabs').tabs('exists', title)){
$('#centerTabs').tabs('select', title);
} else { */
var path='<%=request.getContextPath()%>';
var content = '<iframe scrolling="auto" frameborder="0" src="'+path+url+'" style="width:100%;height:100%;"></iframe>';
$('#centerTabs').tabs('add',{
title:title,
content:content,
closable:true
});
/* } */
}
</script>
<div id="centerTabs" class="easyui-tabs" style="width:100%;height:100%;">
</div>
布局layout.jsp:
<div class="easyui-layout maindiv" >
<div data-options="region:'north'" style="height:10%" href="../jsp/layout/north.jsp"></div>
<!-- <div data-options="region:'east',split:true" title="东" style="width:80px;"></div> -->
<div region="west" split="true" style="width: 15%" title="菜单" href="../jsp/layout/west.jsp"></div>
<div data-options="region:'center',iconCls:'icon-ok'"fit="true" href="../jsp/layout/center.jsp"></div>
<div data-options="region:'south',split:true" style="height:7%;" href="../jsp/layout/south.jsp"></div>
</div>