C#使用Jquery zTree實(shí)現(xiàn)樹(shù)狀結(jié)構(gòu)顯示 異步數(shù)據(jù)加載
C#使用Jquery zTree實(shí)現(xiàn)樹(shù)狀結(jié)構(gòu)顯示_異步數(shù)據(jù)加載
JQuery-Ztree下載地址:https://github.com/zTree/zTree_v3
JQuery-Ztree數(shù)結(jié)構(gòu)演示頁(yè)面: http://www.treejs.cn/v3/demo.php#_101
關(guān)于zTree的詳細(xì)解釋請(qǐng)看演示頁(yè)面,還有zTree幫助Demo。
下面簡(jiǎn)要講解下本人用到的其中一個(gè)實(shí)例(直接上關(guān)鍵代碼了):
異步加載節(jié)點(diǎn)數(shù)據(jù):
A-前臺(tái):
<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", //請(qǐng)求的一般處理程序 autoParam: ["id"], //自帶參數(shù)id--來(lái)自于節(jié)點(diǎn)id otherParam: { "type": "GetUserLevelList" }, //其他參數(shù)自定義 dataFilter: filter, //數(shù)據(jù)過(guò)濾 type: "post" //請(qǐng)求方式 } }; 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); //渲染樹(shù)結(jié)構(gòu) }); </script> <div class="zTreeDemoBackground left"> <ul id="treeDemo" class="ztree"></ul> </div>
B后臺(tái):
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 的摘要說(shuō)明 /// </summary> public class ShoppingHandler : IHttpHandler { //當(dāng)前登錄用戶信息 WeChatUser weChatUser = WeChatIdentity.CurrentUser; public void ProcessRequest(HttpContext context) { string result = ""; if (context.Request["type"] != null) { string requestType = context.Request["type"]; try { switch (requestType) { //獲取用戶信息等級(jí)列表 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) { //編碼,父編碼,名稱,是否打開(kāi),打開(kāi)圖片,關(guān)閉圖片 //{ id:1, pId:0, name:"展開(kāi)、折疊 自定義圖標(biāo)不同", open:true, iconOpen:"../../../css/zTreeStyle/img/diy/1_open.png", iconClose:"../../../css/zTreeStyle/img/diy/1_close.png"}, //編碼,父編碼,名稱,是否打開(kāi),顯示圖片 //{ id: 11, pId: 1, name: "葉子節(jié)點(diǎn)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; } } } }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- C# WPF如何反射加載Geometry幾何圖形數(shù)據(jù)圖標(biāo)
- c# WPF中自定義加載時(shí)實(shí)現(xiàn)帶動(dòng)畫(huà)效果的Form和FormItem
- c# 實(shí)現(xiàn)網(wǎng)頁(yè)加載后將頁(yè)面截取為長(zhǎng)圖片
- C# 根據(jù)表格偶數(shù)、奇數(shù)加載不同顏色
- C# 動(dòng)態(tài)加載程序集信息
- C#中調(diào)用DLL時(shí)未能加載文件或程序集錯(cuò)誤的處理方法(詳解)
- C#中加載dll并調(diào)用其函數(shù)的實(shí)現(xiàn)方法
- c# 動(dòng)態(tài)加載dll文件,并實(shí)現(xiàn)調(diào)用其中的簡(jiǎn)單方法
- C#使用反射加載多個(gè)程序集的實(shí)現(xiàn)方法
- C#實(shí)現(xiàn)動(dòng)態(tài)加載dll的方法
- c#動(dòng)態(tài)加載卸載DLL的方法
- 3種C# 加載Word的方法
相關(guān)文章
使用HttpHanlder處理404:File not found的問(wèn)題
本篇文章小編為大家介紹。使用HttpHanlder處理404:File not found的問(wèn)題。需要的朋友參考下2013-04-04淺析C#?AsyncLocal如何實(shí)現(xiàn)Thread間傳值
這篇文章主要是來(lái)和大家一起討論一下C#?AsyncLocal如何實(shí)現(xiàn)Thread間傳值,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-01-01unity通過(guò)Mesh網(wǎng)格繪制圖形球體
這篇文章主要為大家詳細(xì)介紹了unity通過(guò)Mesh網(wǎng)格繪制圖形球體,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-11-11c# 實(shí)現(xiàn)MD5,SHA1,SHA256,SHA512等常用加密算法源代碼
c# 如何實(shí)現(xiàn)MD5,SHA1,SHA256,SHA512等常用加密算法,需要的朋友可以參考下2012-12-12使用C# 調(diào)用deepseek api接口實(shí)現(xiàn)正常訪問(wèn)的過(guò)程
本文介紹了使用C#調(diào)用deepseek API接口實(shí)現(xiàn)正常訪問(wèn)的方法,包括解決SSL/TLS安全通道問(wèn)題和切換模型等常見(jiàn)問(wèn)題,并提供了默認(rèn)使用的reasoner模型和賬戶余額信息,感興趣的朋友一起看看吧2025-02-02原生實(shí)現(xiàn)C#與Lua相互調(diào)用方法(Unity3D可用)
Lua是一種很好的擴(kuò)展性語(yǔ)言,Lua解釋器被設(shè)計(jì)成一個(gè)很容易嵌入到宿主程序的庫(kù),下面這篇文章主要給大家介紹了關(guān)于原生實(shí)現(xiàn)C#與Lua相互調(diào)用方法,Unity3D可用的相關(guān)資料,需要的朋友可以參考下2022-04-04