①带有父子关系的标准
zTreeNodes
举例:
Js代码
1.var zTreeNodes = [
2.{"id":1, "name":"test1", "nodes":[
3.{"id":11, "name":"test11", "nodes":[
4.{"id":111, "name":"test111"}
5."id":12, "name":"test12"}
②带有父子关系的简单
Array
格式
(isSimpleData)的zTreeNodes
举例:
Js代码
1.var treeNodes = [
2. {"id":1, "pId":0, "name":"test1"},
3.{"id":11, "pId":1, "name":"test11"},
4. {"id":12, "pId":1, "name":"test12"},
5. {"id":111, "pId":11, "name":"test111"},
例子:
(Java代码)
①在页面引用
zTree的js和css:
Html代码
1.
<!-- ZTree树形插件 -->
2.<link
rel="stylesheet"
href="<%=root%>/Web/common/css/zTreeStyle/zTreeStyle.css"type
="text/css">
3.<!-- <link rel="stylesheet" href="<%=root%>/Web/common/css/zTreeStyle/zTreeIcons.css" type="text/css"> -->
4.<script ype="text/javascript"src="<%=root%>/Web/common/js/jquery-ztree-2.5.min.js"
></script>
asp.net 内容如下:
/// <summary>/// 显示树导航菜单
/// </summary>
public void InitInfo()
{
string UserId = RequestSession.GetSessionUser().UserId.ToString()//用户ID
DataTable dt = systemidao.GetMenuHtml(UserId)
if (DataTableHelper.IsExistRows(dt))
{
DataView dv = new DataView(dt)
dv.RowFilter = "ParentId = '0'"
foreach (DataRowView drv in dv)
{
strHtml.Append("<li>")
strHtml.Append("<div>" + drv["Menu_Name"] + "</div>")
//创建子节点
strHtml.Append(GetTreeNode(drv["Menu_Id"].ToString(), dt))
strHtml.Append("</li>")
}
}
}
/// <summary>
/// 创建子节点
/// </summary>
/// <param name="parentID">父节点主键</param>
/// <param name="dtMenu"></param>
/// <returns></returns>
public string GetTreeNode(string parentID, DataTable dtNode)
{
StringBuilder sb_TreeNode = new StringBuilder()
DataView dv = new DataView(dtNode)
dv.RowFilter = "ParentId = '" + parentID + "'"
if (dv.Count > 0)
{
sb_TreeNode.Append("<ul>")
foreach (DataRowView drv in dv)
{
sb_TreeNode.Append("<li>")
DataTable IsJudge = DataTableHelper.GetNewDataTable(dtNode, "ParentId = '" + drv["Menu_Id"].ToString() + "'")//判断是否有下级菜单
if (DataTableHelper.IsExistRows(IsJudge))
{
sb_TreeNode.Append("<div>" + drv["Menu_Name"] + "</div>")
}
else
{
sb_TreeNode.Append("<div title=\"" + drv["Menu_Title"] + "\" onclick=\"NavMenu('" + drv["NavigateUrl"] + "','" + drv["Menu_Name"] + "')\"><img src=\"/Themes/Images/32/" + drv["Menu_Img"] + "\" width=\"16\" height=\"16\" />" + drv["Menu_Name"] + "</div>")
}
//创建子节点
sb_TreeNode.Append(GetTreeNode(drv["Menu_Id"].ToString(), dtNode))
sb_TreeNode.Append("</li>")
}
sb_TreeNode.Append("</ul>")
}
return sb_TreeNode.ToString()
}