<script type="text/javascript">
//左侧菜单
var curMenu = null, zTree_Menu = null;
var setting = {
view: {
showLine: true,
selectedMulti: false,
dblClickExpand: true
},
data: {
simpleData: {
enable: true
},
key: {
url: "xUrl"
}
},
callback: {
onNodeCreated: this.onNodeCreated,
beforeClick: this.beforeClick,
onClick: this.onClick
}
};
//数据格式
// [{ id:2, pId:0, name:"应急准备", href:"##", open:true }, { id:8, pId:2, name:"应急队伍", href:"emergency/emergencySanitationEmergencyTeam.do?method=list" }, { id:10, pId:2, name:"应急物资", href:"##" }, { id:11, pId:10, name:"采购申请", href:"emergency/logisticsPurchaseOrderManage.do?method=getListEasyUI" }]
//注意需要将集合的[]去除 然后在通过这样的方式转出数组 var zNodes =new Array(${list});
var zNodes =new Array(${list});
console.log(zNodes);
function onClick(e, treeId, node) {
if((node.href).indexOf("##")>-1){
}else{
}
}
function beforeClick(treeId, node) {
if (node.isParent) {
if (node.level === 0) {
var pNode = curMenu;
while (pNode && pNode.level !==0) {
pNode = pNode.getParentNode();
}
if (pNode !== node) {
var a = $("#" + pNode.tId + "_a");
a.removeClass("cur");
zTree_Menu.expandNode(pNode, false);
}
a = $("#" + node.tId + "_a");
a.addClass("cur");
var isOpen = false;
for (var i=0,l=node.children.length; i<l; i++) {
if(node.children[i].open) {
isOpen = true;
break;
}
}
if (isOpen) {
zTree_Menu.expandNode(node, true);
curMenu = node;
} else {
zTree_Menu.expandNode(node.children[0].isParent?node.children[0]:node, true);
curMenu = node.children[0];
}
} else {
zTree_Menu.expandNode(node);
}
}
return !node.isParent;
}
$(document).ready(function(){
$.fn.zTree.init($("#treeDemo"), setting, zNodes);
zTree_Menu = $.fn.zTree.getZTreeObj("treeDemo");
curMenu = zTree_Menu.getNodes()[0];
zTree_Menu.selectNode(curMenu);
var a = $("#" + zTree_Menu.getNodes()[0].tId + "_a");
a.addClass("cur");
});
</script>