$(function() {
$.ajax({
async : false,
url : getRootPath() + '/getPower.action',
type : 'post',
dataType : 'JSON',
success : function(data) {
addNav(data);
}
});
// 导航菜单绑定初始化
$("#menu").accordion({ // 初始化accordion
title : '导航菜单',
fit : true,
border : true,
animate : true
});
});
function addNav(data) {
$('#menu').accordion();
$.each(data, function(i, m) {
var menulist = '';
var mid = m.id;
menulist += '<ul>';
menulist += '<div id = "tree' + mid + '" ></div>';
menulist += '</ul>';
console.info(menulist);
$('#menu').accordion('add', {
title : m.text,
content : "<ul id='tree"+mid+"' ></ul>",
iconCls : 'icon ' + 'icon-sys',
selected : true,
collapsible : true
});
$.parser.parse();
addTree(mid, m.children);
});
}
function addTree(mid, menus) {
$("#tree"+ mid).tree(
{
data : menus,
type : 'json',
animate : true,
onSelect : function(node) {
node.state == 'closed' ? $(this)
.tree('expand', node.target) : $(this).tree(
'collapse', node.target);
},
onClick : function(node) {
if ($('#' + mid).tree('isLeaf', node.target)) {
addTab(node.text, node.url, node.icon);
}
}
});
}
这样写有什么问题吗,为什么加载出来第一级的菜单有,但是往下的tree就出不来了,试了半天找不出原因,请各位前辈帮我看看