C#使用Jquery zTree實現(xiàn)樹狀結構顯示 異步數(shù)據(jù)加載
C#使用Jquery zTree實現(xiàn)樹狀結構顯示_異步數(shù)據(jù)加載
JQuery-Ztree下載地址:https://github.com/zTree/zTree_v3
JQuery-Ztree數(shù)結構演示頁面: http://www.treejs.cn/v3/demo.php#_101
關于zTree的詳細解釋請看演示頁面,還有zTree幫助Demo。
下面簡要講解下本人用到的其中一個實例(直接上關鍵代碼了):
異步加載節(jié)點數(shù)據(jù):
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"], //自帶參數(shù)id--來自于節(jié)點id otherParam: { "type": "GetUserLevelList" }, //其他參數(shù)自定義 dataFilter: filter, //數(shù)據(jù)過濾 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: "葉子節(jié)點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; } } } }
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
- C# WPF如何反射加載Geometry幾何圖形數(shù)據(jù)圖標
- c# WPF中自定義加載時實現(xiàn)帶動畫效果的Form和FormItem
- c# 實現(xiàn)網(wǎng)頁加載后將頁面截取為長圖片
- C# 根據(jù)表格偶數(shù)、奇數(shù)加載不同顏色
- C# 動態(tài)加載程序集信息
- C#中調(diào)用DLL時未能加載文件或程序集錯誤的處理方法(詳解)
- C#中加載dll并調(diào)用其函數(shù)的實現(xiàn)方法
- c# 動態(tài)加載dll文件,并實現(xiàn)調(diào)用其中的簡單方法
- C#使用反射加載多個程序集的實現(xiàn)方法
- C#實現(xiàn)動態(tài)加載dll的方法
- c#動態(tài)加載卸載DLL的方法
- 3種C# 加載Word的方法
相關文章
使用HttpHanlder處理404:File not found的問題
本篇文章小編為大家介紹。使用HttpHanlder處理404:File not found的問題。需要的朋友參考下2013-04-04淺析C#?AsyncLocal如何實現(xiàn)Thread間傳值
這篇文章主要是來和大家一起討論一下C#?AsyncLocal如何實現(xiàn)Thread間傳值,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學習一下2024-01-01c# 實現(xiàn)MD5,SHA1,SHA256,SHA512等常用加密算法源代碼
c# 如何實現(xiàn)MD5,SHA1,SHA256,SHA512等常用加密算法,需要的朋友可以參考下2012-12-12使用C# 調(diào)用deepseek api接口實現(xiàn)正常訪問的過程
本文介紹了使用C#調(diào)用deepseek API接口實現(xiàn)正常訪問的方法,包括解決SSL/TLS安全通道問題和切換模型等常見問題,并提供了默認使用的reasoner模型和賬戶余額信息,感興趣的朋友一起看看吧2025-02-02原生實現(xiàn)C#與Lua相互調(diào)用方法(Unity3D可用)
Lua是一種很好的擴展性語言,Lua解釋器被設計成一個很容易嵌入到宿主程序的庫,下面這篇文章主要給大家介紹了關于原生實現(xiàn)C#與Lua相互調(diào)用方法,Unity3D可用的相關資料,需要的朋友可以參考下2022-04-04