zoukankan      html  css  js  c++  java
  • ASP返回JQuery EasyUI树形要求的JSON格式

    根据http://blog.csdn.net/apollokk/article/details/41382479中提供的数据将结果格式化为JQuery EasyUI树形要求的JSON格式

    <%
    Response.Charset="utf-8"
    Session.CodePage=65001
    
    Set conn = Server.CreateObject("ADODB.Connection") 
    connstr="Driver={SQL Server};server=.sqlexpress;uid=sa;pwd=sa;database=dgmloa;"
    conn.Open connstr 
    
    set rs = conn.execute("exec [pGetDepartment]")
    json = ""
    if not rs.eof then
    	json = "["
    	'第一条数据
    	json = json & "{""id"":" & rs("id") & ",""text"":""" & Replace(rs("department"),"""","""") & """"
    	'当前层级
    	level = rs("level")
    	rs.movenext
    	while not rs.eof
    		if level = rs("level") then						'如果是同级则闭合
    			json = json & "},"
    		elseif level > rs("level") then					'如果遇到上一级则根据级别之差进行闭合
    			json = json & "}"
    			for i = 1 to (level - rs("level"))
    				json = json & "]}"
    			next
    			json = json & ","
    		else											'如果遇到下级则添加前缀
    			json = json & ",""children"":["
    		end if
    		'输出本条数据
    		json = json & "{""id"":" & rs("id") & ",""text"":""" & Replace(rs("department"),"""","""") & """"
    		level = rs("level")
    		rs.movenext	
    	wend
    	'最后的闭合
    	for i = 1 to level
                 json = json & "}]"
            next
    	Response.Write(json)
    end if
    
    if rs.state=1 then rs.close
    if conn.state=1 then conn.close
    set rs=nothing
    set conn=nothing
    %>


  • 相关阅读:
    Nginx 和 PHP的安装配置
    hdu1166 敌兵布阵
    乘法逆元详解
    SPFA算法
    Kruskal算法&Prim算法
    WC2018 文艺汇演《退役的你》
    HDU2577 How to Type
    裴蜀定理的证明
    CSP J/S 2019受虐记
    Dijkstra算法详解
  • 原文地址:https://www.cnblogs.com/apollokk/p/6713864.html
Copyright © 2011-2022 走看看