jsp
<ul id="menuTree" style="width:auto;margin: 5px" ></ul>
js
var menuTree;
$(function() {
menuTree = $('#menuTree').tree({
url : '${path }/resource/menuTree',
parentField : 'pid',
lines : true,
onClick : function(node) {
//是叶子节点则打开或跳转到tab页。
if ($('#menuTree').tree('isLeaf',node.target)) {
addTab(node.attributes, node.text);
}
},
onBeforeLoad: function (node, param) {
},
onLoadSuccess:function(){
}
});
});
function addTab(url,text) {
var opts = {
title : text,
border : false,
closable : true,
fit : true/*,
iconCls : node.iconCls*/
};
if (url && url.indexOf("http") == -1) {
url = '${path }' + url;
}
opts.content = '<iframe src="' + url + '" frameborder="0" style="border:0;width:100%;height:100%;"></iframe>';
var t = $('#index_tabs');
if (t.tabs('exists', opts.title)) {
t.tabs('select', opts.title);
} else {
t.tabs('add', opts);
}
}
效果图
control层
List<Resource> resourceList = this.selectByType(RESOURCE_MENU);
if (resourceList == null) {
return trees;
}
for (Resource resource : resourceList) {
Tree tree = new Tree();
tree.setId(resource.getId());
tree.setPid(resource.getPid());
tree.setText(resource.getName());
tree.setIconCls(resource.getIcon());
tree.setAttributes(resource.getUrl());
tree.setOpenMode(resource.getOpenMode());
tree.setState(resource.getOpened());
trees.add(tree);
}
return trees;