ztree_demo.js

//设置节点样式 function setFontCss(treeId, treeNode) { return treeNode.level == 2 ? { color: "#687885" }: {}; } var zTreeBeforeCheck=function(){ debugger var tree=$.fn.zTree.getZTreeObj('treeDemo'); nodes=tree.getCheckedNodes(true); console.log(JSON.stringify(nodes)); } var setting = { check: { chkStyle: "checkbox", enable: true, chkboxType: { "Y": "", "N": "" }, }, view: { showIcon: false, //不显示图标setFontCss fontCss: setFontCss, //样式 expandSpeed: 300 //展示速度 }, data: { simpleData: { enable: true, idKey: "id", pIdKey: "pId", rootPId: "pId" } }, callback: { beforeClick: zTreeBeforeCheck } }; $(document).ready(function() { var x = [{ name: '总结点', id: 0, pId: 0, open: true, isParent: true }, { name: '一级节点1', id: 1, pId: 0, open: true, isParent: true }, { name: '一级节点11', id: 11, pId: 1, open: true, isParent: true }, { name: '一级节点111', id: 111, pId: 11, open: true, isParent: true }, { name: '一级节点1111', id: 1111, pId: 111, open: true, isParent: false } , { name: '一级节点12', id: 12, pId: 1, open: true, isParent: false } , { name: '一级节点2', id: 2, pId: 0, open: true, isParent: true }, { name: '一级节点3', id: 3, pId: 0, open: true, isParent: true } , { name: '一级节点31', id: 31, pId: 3, open: true, isParent: true }, { name: '一级节点311', id: 311, pId: 31, open: true, isParent: true } , { name: '一级节点4', id: 4, pId: 0, open: true, isParent: true } ]; $.fn.zTree.init($("#treeDemo"), setting, x); });

JSRUN前端笔记, 是针对前端工程师开放的一个笔记分享平台,是前端工程师记录重点、分享经验的一个笔记本。JSRUN前端采用的 MarkDown 语法 (极客专用语法), 这里只属于前端工程师。