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
    %>


  • 相关阅读:
    Python-内置函数
    Python-匿名函数
    Python-函数递归-二分法
    Python-函数递归
    Day4-函数
    CSS-定位
    CSS-文本属性,文字属性
    CSS-浮动
    CSS-盒模型
    CSS-继承和层叠
  • 原文地址:https://www.cnblogs.com/apollokk/p/6713864.html
Copyright © 2011-2022 走看看