jquery,tree无限级树形菜单+简单实用案例

技术小胖子 2017-11-04

java 根目录 jquery page type utf-8 input

jquery,tree无限级树形菜单+简单实用案例

我在项目中用到产品类别的树形。各种地方都要用。 我就封装起来,方便以后调用。

记录下来,希望给新手们提供帮助。要记得导入jquery.js  tree.js 哦


<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <link rel="stylesheet" type="text/css" href="page/plugin/zTree/zTreeStyle/zTreeStyle.css"/> <script type="text/javascript" src="page/js/jquery.ztree-2.6.min.js"></script>  <div id="goodsCategoryTree" class="tree"></div> <input type="hidden" id="goodsCategoryTreeSelect" name="goodsCategoryTreeSelect"/> <input type="hidden" id="goodsCategoryTreeSelectName" name="goodsCategoryTreeSelectName"/> <script> var goodsCategoryTree; var treeNodes = eval('(${web.goodsCategoryJson})');//为节点进行json赋值  function getCheckTreeNode(event, treeId, treeNode){//获取选中节点id,name 	var tId = treeNode.cateID; 	var name = treeNode.cateName; 	$("#goodsCategoryTreeSelect").val(tId); 	$("#goodsCategoryTreeSelectName").val(name); 	$("#goodsCategoryTreeSelect").focus(); } var setting = {//参数设置 	isSimpleData : true,              //数据是否采用简单 Array 格式,默认false 	treeNodeKey : "cateID",               //在isSimpleData格式下,当前节点id属性 	nameCol : "cateName", 	treeNodeParentKey : "parentCateID",        //在isSimpleData格式下,当前节点的父节点id属性 	showLine : true,                  //是否显示节点间的连线 	checkable : false,                  //每个节点上是否显示 CheckBox 	callback : { 		click: getCheckTreeNode 	} }; goodsCategoryTree = $("#goodsCategoryTree").zTree(setting, treeNodes);//初始化树形  </script> 

Json 数据字符串
web.goodsCategoryJson =  [{"cateID":"05E19A7462A148709CE295CA2295BD7E","cateName":"计算机","parentCateID":"43242"},{"cateID":"43242","cateName":"电器","parentCateID":"1"},{"cateID":"43243","cateName":"服装1","parentCateID":"1"},{"cateID":"43244","cateName":"女装","parentCateID":"43243"},{"cateID":"43245","cateName":"根目录","parentCateID":"43243"},{"cateID":"43246","cateName":"根目录6","parentCateID":"43244"},{"cateID":"43247","cateName":"根目录7","parentCateID":"43245"},{"cateID":"43248","cateName":"根目录8","parentCateID":"43246"},{"cateID":"43249","cateName":"根目录9","parentCateID":"43247"},{"cateID":"43250","cateName":"根目录0","parentCateID":"43248"},{"cateID":"43251","cateName":"根目录1","parentCateID":"43249"},{"cateID":"43252","cateName":"根目录2","parentCateID":"43250"},{"cateID":"43253","cateName":"根目录3","parentCateID":"2"},{"cateID":"1","cateName":"通用分类","parentCateID":"-1"},{"cateID":"2","cateName":"频道分类","parentCateID":"-1"}]




      本文转自yjflinchong 51CTO博客,原文链接:http://blog.51cto.com/yjflinchong/1165072,如需转载请自行联系原作者


登录 后评论
下一篇
云栖号资讯小编
20006人浏览
2020-07-13
相关推荐
ASP.NET 实用资料[转]
3231人浏览
2017-11-26 11:32:00
超强1000个jquery插件!
2399人浏览
2011-12-18 20:29:00
树结构控件:jQuery zTree
1343人浏览
2016-12-21 13:48:00
权限管理系统 OpenAuth.Net
1260人浏览
2017-06-02 16:47:00
js Tree - 树形菜单插件
1405人浏览
2011-10-27 13:07:00
PHP无限递归菜单的实现流程
1267人浏览
2017-11-15 15:30:00
0
0
0
1178