C#使用Jquery zTree实现树状结构显示 异步数据加载
程序员文章站
2022-08-11 20:56:41
c#使用jquery ztree实现树状结构显示_异步数据加载
jquery-ztree下载地址:https://github.com/ztree/ztree_v3
j...
c#使用jquery ztree实现树状结构显示_异步数据加载
jquery-ztree下载地址:https://github.com/ztree/ztree_v3
jquery-ztree数结构演示页面:
关于ztree的详细解释请看演示页面,还有ztree帮助demo。
下面简要讲解下本人用到的其中一个实例(直接上关键代码了):
异步加载节点数据:
a-前台:
<link href="ztree_v3-master/css/ztreestyle/ztreestyle.css" rel="stylesheet" /> <script src="ztree_v3-master/js/jquery.ztree.core.js" type="text/javascript"></script> <script language="javascript" type="text/javascript"> var setting = { async: { enable: true, url: "../handler/shoppinghandler.ashx", //请求的一般处理程序 autoparam: ["id"], //自带参数id--来自于节点id otherparam: { "type": "getuserlevellist" }, //其他参数自定义 datafilter: filter, //数据过滤 type: "post" //请求方式 } }; function filter(treeid, parentnode, childnodes) { if (!childnodes) return null; for (var i = 0, l = childnodes.length; i < l; i++) { childnodes[i].name = childnodes[i].name.replace(/\.n/g, '.'); } return childnodes; } $(document).ready(function () { $.fn.ztree.init($("#treedemo"), setting); //渲染树结构 }); </script> <div class="ztreedemobackground left"> <ul id="treedemo" class="ztree"></ul> </div>
b后台:
using mobilebusiness.common.data; using mobilebusiness.library.passport; using mobilebusiness.shopping.data; using mobilebusiness.shopping.data.common; using mobilebusiness.shopping.data.entity; using mobilebusiness.web.library.script; using newtonsoft.json; using system; using system.collections.generic; using system.linq; using system.web; using shoppingdata = mobilebusiness.shopping.data.entity; namespace mobilebusiness.shopping.businessmanage.handler { /// <summary> /// shopping 的摘要说明 /// </summary> public class shoppinghandler : ihttphandler { //当前登录用户信息 wechatuser wechatuser = wechatidentity.currentuser; public void processrequest(httpcontext context) { string result = ""; if (context.request["type"] != null) { string requesttype = context.request["type"]; try { switch (requesttype) { //获取用户信息等级列表 case "getuserlevellist": result = this.getuserlevellist(context); break; default: break; } } catch (exception ex) { result = ex.message; } } context.response.contenttype = "text/html"; context.response.write(result); context.response.end(); } private string getuserlevellist(httpcontext context) { string parentuserphone = context.request["id"]; return getusercollbyphone(parentuserphone); } private string getusercollbyphone(string phone) { //编码,父编码,名称,是否打开,打开图片,关闭图片 //{ id:1, pid:0, name:"展开、折叠 自定义图标不同", open:true, iconopen:"../../../css/ztreestyle/img/diy/1_open.png", iconclose:"../../../css/ztreestyle/img/diy/1_close.png"}, //编码,父编码,名称,是否打开,显示图片 //{ id: 11, pid: 1, name: "叶子节点1", icon: "../../../css/ztreestyle/img/diy/2.png"}, list<object> result = new list<object>(); shoppingdata.userinfocollection usercoll = shoppingdata.userinfoadapter.instance.loadbyparentuserphone(phone); usercoll.foreach(user => { result.add(new { id = user.phone, pid = phone, name = user.username, isparent = shoppingdata.userinfoadapter.instance.loadbyparentuserphone(user.phone).count > 0 ? true : false }); }); return jsonconvert.serializeobject(result); } public bool isreusable { get { return false; } } } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
上一篇: SQL行转列、列转行的简单实现
下一篇: VS2012 程序打包部署图文详解