在最近的项目应用中,找到了zTree免费的好东西,这里总结一下:

源码下载:http://www.ztree.me/

效果是酱紫的:

 

前台代码:

  样式和脚本

  <link rel="stylesheet" href="JavaScript/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css" />
<script type="text/javascript" src="JavaScript/zTree/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="JavaScript/zTree/js/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript">
var curMenu = null, zTree_Menu = null;
var setting = {
view: {
showLine: true,
selectedMulti: false,
dblClickExpand: false
},
data: {
simpleData: {
enable:true,
idKey: "id",
pIdKey: "pId",
rootPId: ""
}
},
callback: {
beforeClick: function(treeId, treeNode) {
var zTree = $.fn.zTree.getZTreeObj("tree");
if (treeNode.isParent) {
zTree.expandNode(treeNode);
return false;
} else {
demoIframe.attr("src",treeNode.file);
return true;
}
}
}
};
var zNodes=<%=sbData.ToString() %>; 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(){
var t = $("#tree");
t = $.fn.zTree.init(t, setting, zNodes);
demoIframe = $("#testIframe");
demoIframe.bind("load", loadReady);
var zTree = $.fn.zTree.getZTreeObj("tree");
zTree.selectNode(zTree.getNodeByParam("id", 101)); }); function loadReady() {
var bodyH = demoIframe.contents().find("body").get(0).scrollHeight,
htmlH = demoIframe.contents().find("html").get(0).scrollHeight,
maxH = Math.max(bodyH, htmlH), minH = Math.min(bodyH, htmlH),
h = demoIframe.height() >= maxH ? minH:maxH ;
if (h < 530) h = 530;
demoIframe.height(h);
}
</script>
<style>
body {
margin:0; padding:0;
text-align: center;
}
div, p, table, th, td {
list-style:none;
margin:0; padding:0;
color:#333; font-size:12px;
font-family:dotum, Verdana, Arial, Helvetica, AppleGothic, sans-serif;
}
#testIframe {margin-left: 10px;} .ztree li a.level0 {width:200px;height: 20px; text-align: center; display:block; background-color: #66A3D1; border:1px silver solid;}
.ztree li a.level0.cur {background-color: #66A3D2; }
.ztree li a.level0 span {display: block; color: white; padding-top:3px; font-size:12px; font-weight: bold;word-spacing: 2px;}
.ztree li a.level0 span.button { float:right; margin-left: 10px; visibility: visible;display:none;}
.ztree li span.button.switch.level0 {display:none;}
.ztree li span.button.icon04_ico_docu{margin-right:2px; background: url(JavaScript/zTree/css/zTreeStyle/img/diy/6.png) no-repeat scroll 0 0 transparent; vertical-align:top; *vertical-align:middle}
.ztree li span.button.icon06_ico_docu{margin-right:2px; background: url(JavaScript/zTree/css/zTreeStyle/img/diy/8.png) no-repeat scroll 0 0 transparent; vertical-align:top; *vertical-align:middle}
</style>

  页面布局

<div>
<table border="0px" width="100%" align="left">
<tr>
<td colspan="2">
<iframe id="Iframe1" name="testIframe" frameborder="0" scrolling="no" width="100%" height="80" src="PageTop.aspx"></iframe>
</td>
</tr>
<tr>
<td width="15%" align="left" valign="top" style="border-right:#999 1px dashed;">
<ul id="tree" class="ztree" style="width:220px; height:600px; overflow:auto; margin:0px; border-style:none;"></ul>
</td>
<td width="85%" align="left" valign="top">
<iframe id="testIframe" name="testIframe" frameborder="0" scrolling="auto" width="100%" height="600px" src="blank.htm" style=" margin:0px;"></iframe>
</td>
</tr>
</table>
</div>

后台代码:

  SqlDAL sqlAccess = new SqlDAL();
public StringBuilder sbData = new StringBuilder();
protected void Page_Load(object sender, EventArgs e)
{
//1:项目 2:名称 3:操作
sbData.Append("[");
sbData.Append("{ id:1, pId:0, name:'项目', open:true},");
//加载项目
string strSql = "Select * from dbo.t_Menu";
System.Data.DataSet ds = sqlAccess.ReadFromDB(strSql);
if (ds != null && ds.Tables.Count > && ds.Tables[].Rows.Count > )
{
System.Data.DataTable dt = ds.Tables[];
for (int i = ; i < dt.Rows.Count; i++)
{
string strProName = dt.Rows[i]["MenuName"].ToString();
string strId = "" + Convert.ToString(i + );
string strPid = "";
//sbData.Append(string.Format("{id:"+"{0}, pId:{1}, name:'{2}'"+"},", strId, strPid, strProName));//容易报错
sbData.Append("{ id:" + strId + ", pId:" + strPid + ", name:'" + strProName + "'},");
//加载名称
strSql = string.Format("Select * from dbo.t_Pars where MenuID='{0}'", dt.Rows[i]["ID"].ToString());
System.Data.DataSet ds2 = sqlAccess.ReadFromDB(strSql);
if (ds2 != null && ds2.Tables.Count > && ds.Tables[].Rows.Count > )
{
System.Data.DataTable dt2 = ds2.Tables[];
string strId2 = strId + "";//路径需要修改啊
sbData.Append("{ id:" + strId2 + ", pId:" + strId + ", name:'录入',iconSkin:'icon04',file:'Project/test.aspx'},");
for (int j = ; j < dt2.Rows.Count; j++)
{
strProName = dt2.Rows[j]["Name"].ToString() + "图";
strId2 = strId + Convert.ToString(j + );//路径需要修改
sbData.Append("{ id:" + strId2 + ", pId:" + strId + ", name:'" + strProName + "',iconSkin:'icon06',file:'Project/test.aspx'},");
}
}
}
}
//加载定制
sbData.Append("{ id:2, pId:0, name:'项目管理', open:true},");
sbData.Append("{ id:21, pId:2, name:'项目制定'},");
sbData.Append("{ id:211, pId:21, name:'添加',iconSkin:'icon04',file:'Project/test.aspx'}"); sbData.Append("]");
}

PS:

在此之前使用Ajax请求获取Json数据,Json数据是获取到了,可是,页面的就是显示不出来,感觉好奇怪啊,哎,Teng!

下面是获取代码,问题先记录下

$.post("AJAX/GetDynamicMenu.ashx",{action:"1"},function(data,status){
if(status=="success")
{
var zNodes = data; var t = $("#tree");
t = $.fn.zTree.init(t, setting, zNodes);
demoIframe = $("#testIframe");
demoIframe.bind("load", loadReady);
var zTree = $.fn.zTree.getZTreeObj("tree");
zTree.selectNode(zTree.getNodeByParam("id", 101));
}
});

待续......

ASP.NET中使用开源插件zTree的小结的更多相关文章

  1. ASP.NET中使用jQuery插件实现图片幻灯效果

    参照网上的资料及提供的jQuery插件实现图片幻灯效果. 1.页面前台代码: //头部引用 <head runat="server"><title>< ...

  2. 第三方开源插件zTree的使用

    zTree实现树形节点勾选效果图 使用流程: JS文件导入和引用 css文件导入和引用 demo代码 JS.css文件导入和引用 3个核心JS文件及两个核心css文件 demo相关代码: <!D ...

  3. Jquery插件Ztree使用所遇问题

    问题1.$.fn.zTree为空或为Undefined 我在MVC中引用Jquery插件Ztree的JS并不存任何问题,而当我将Ztree的js引入项目中,就出现$.fn.zTree为空或为Undef ...

  4. ASP.NET中常用的几个李天平开源公共类LTP.Common,Maticsoft.DBUtility,LtpPageControl

    ASP.NET中常用的几个开源公共类: LTP.Common.dll: 通用函数类库     源码下载Maticsoft.DBUtility.dll 数据访问类库组件     源码下载LtpPageC ...

  5. ASP.NET中常用的几个李天平开源公共类LTP.Common,Maticsoft.DBUtility,LtpPageControl (转)

    ASP.NET中常用的几个开源公共类: LTP.Common.dll: 通用函数类库     源码下载Maticsoft.DBUtility.dll 数据访问类库组件     源码下载LtpPageC ...

  6. C#实现多级子目录Zip压缩解压实例 NET4.6下的UTC时间转换 [译]ASP.NET Core Web API 中使用Oracle数据库和Dapper看这篇就够了 asp.Net Core免费开源分布式异常日志收集框架Exceptionless安装配置以及简单使用图文教程 asp.net core异步进行新增操作并且需要判断某些字段是否重复的三种解决方案 .NET Core开发日志

    C#实现多级子目录Zip压缩解压实例 参考 https://blog.csdn.net/lki_suidongdong/article/details/20942977 重点: 实现多级子目录的压缩, ...

  7. ASP.NET中后台数据和前台控件的绑定

    关于ASP.NET中后台数据库和前台的数据控件的绑定问题 最近一直在学习个知识点,自己创建了SQL Server数据库表,想在ASP.NET中连接数据库,并把数据库中的数据显示在前台,注意,这里的数据 ...

  8. Metronic 使用到的开源插件汇总

    Metronic 是一套完整的 UI 模板,但不仅仅是模板,更应该说是一个 UI 框架.它除了提供了大量网页模板,也提供了非常多的 UI 组件,并且应用了众多 jQuery 插件.通过这些资源的整合, ...

  9. ASP.NET中UEditor使用

    ASP.NET中UEditor使用 0.ueditor简介 UEditor是由百度WEB前端研发部开发的所见即所得的开源富文本编辑器,具有轻量.可定制.用户体验优秀等特点.开源基于BSD协议,所有源代 ...

随机推荐

  1. UVa657 The die is cast

    // 题意:给一个图案,其中'.'表示背景,非'.'字符组成的连通块为筛子.每个筛子里又包含两种字符,其中'X'组成的连通块表示筛子上的点 // 统计每个筛子里有多少个"X"连通块 ...

  2. UVa297 Quadtrees

    // UVa297 Quadtrees // 题意:给两棵四分树的先序遍历,求二者合并之后(黑色部分合并)黑色像素的个数.p表示中间结点,f表示黑色(full),e表示白色(empty) // 算法: ...

  3. Note of IOS 7 - Views

    1. Views presentation: A view (an object whose class is UIView or a subclass of UIView) knows how to ...

  4. 2015南阳CCPC L - Huatuo's Medicine 水题

    L - Huatuo's Medicine Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description Huatuo was a famous ...

  5. Android Socket编程学习笔记

    http://blog.csdn.net/eyu8874521/article/details/8847173 度娘给出的描述:通常也称作"套接字",用于描述IP地址和端口,是一个 ...

  6. iOS开发——网络编程Swift篇&(五)同步Post方式

    同步Post方式 // MARK: - 同步Post方式 func synchronousPost() { //创建NSURL对象 var url:NSURL! = NSURL(string: &qu ...

  7. SQL用法总结

    1.创建数据库语句 create table persons( 'id' INT NOT NULL AUTO_INCREMENT, ) NOT NULL, ) NOT NULL, PRIMARY KE ...

  8. 增加字段关联插件 For PHPCMS V9 免费版

    增加字段关联插件 For PHPCMS V9 免费版 第一:增加字段选择关联 第二:关联后的效果 烈火下载友情提示:增加方法详见附件内的说明文档. 附件下载

  9. 使用mii-tool设置网卡速率

    转载:http://washion2008.blog.163.com/blog/static/144227201001711537158/ 在ubuntu中,mii-tool 是属于net-tools ...

  10. python--json & pickle 模块

    用于序列化的两个模块 json,用于字符串 和 python数据类型间进行转换 pickle,用于python特有的类型 和 python的数据类型间进行转换 Json模块提供了四个功能:dumps. ...