小编给大家分享一下Jquery树插件zTree如何实现菜单树,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
具体内容如下
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Title</title>
<link href="JS/tool/zTree/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" />
<script src="JS/jquery-1.11.1.min.js"></script>
<script src="JS/tool/zTree/js/jquery.ztree.core-3.5.js"></script>
<script src="JS/tool/zTree/js/jquery.ztree.excheck-3.5.js"></script>
</head>
<body >
<div class="mainbody-left">
<div class="vvtree dept-tree left">
<ul id="menu_tree_left" class="ztree"></ul>
</div>
</div>
<script>
var settingLeft = {
view: {
dblClickExpand: false,//双击节点时,是否自动展开父节点的标识
showLine: false,//是否显示节点之间的连线
showIcon: true,
fontCss: { 'color': 'white', 'font-weight': 'normal' },//字体样式函数
selectedMulti: false //设置是否允许同时选中多个节点
},
check: {
//chkboxType: { "Y": "ps", "N": "ps" },
chkStyle: "checkbox",//复选框类型
enable: false //每个节点上是否显示 CheckBox
},
data: {
simpleData: {//简单数据模式
enable: true,
idKey: "id",
pIdKey: "pId",
rootPId: ""
}
},
callback: {
beforeClick: function (treeId, treeNode) {
zTree = $.fn.zTree.getZTreeObj("menu_tree_vehicle");
if (treeNode.isParent) {
zTree.expandNode(treeNode);//如果是父节点,则展开该节点
} else {
zTree.checkNode(treeNode, !treeNode.checked, true, true);//单击勾选,再次单击取消勾选
}
}//,
// onCheck: onCheck
}
};
$(function () {
//初始化菜单树
var zNodes = [
{ id: 0, pId: -1, name: "一级部门", open: true },
{ id: 1, pId: 0, name: "二级部门1", open: false },
{ id: 2, pId: 1, name: "三级部门1" },
{ id: 3, pId: 1, name: "三级部门2" },
{ id: 4, pId: 0, name: "二级部门2", open: false },
{ id: 5, pId: 4, name: "三级部门3" },
{ id: 6, pId: 4, name: "三级部门4", open: false },
{ id: 7, pId: 6, name: "四级部门1" },
{ id: 8, pId: 6, name: "四级部门2" },
{ id: 9, pId: 0, name: "二级部门3" },
{ id: 10, pId: 0, name: "二级部门4" }
];
$.fn.zTree.init($("#menu_tree_left"), settingLeft, zNodes);
});
</script>
</body>
</html>
以上是“Jquery树插件zTree如何实现菜单树”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注编程网行业资讯频道!