动态载入树 (ASP+数据库)

ASP+ACCESS 在数据量达100万条记录下,载入速度仍然惊人....

// 网上转载. 忘了作者... : )

//********************** Index.asp ************************//

1 < %@LANGUAGE = " VBSCRIPT " CODEPAGE = " 936 " % >
2 < % Option Explicit % >
3 < html >
4 < head >
5 < metahttp - equiv = " Content-Type " content = " text/html;charset=gb2312 " >
6 < title > tree </ title >
7 < linkhref = " css/style.css " rel = " stylesheet " type = " text/css " >
8 < scriptlanguage = " JavaScript " >
9 < ! --
10 vard1,d2;
11
12 function expand(id)
13 {
14 vard = new Date ();
15 d1 = d.valueOf();
16
17 vars_id = eval ( " s " + id);
18 vardir_id = eval ( " dir " + id);
19 if (s_id.href! = ' ')
20 {
21 // window.open(s_id.href);
22 // or
23 // top.frames[ ' FrameName'].location.href=s_id.href;
24 }
25
26 switch(dir_id.open)
27 {
28 // 改变 " + " , " -"
29 case " true " :
30 {
31 with (dir_id)
32 {
33 innerText = " + " ;
34 open = " false " ;
35 className = ' dirclose';
36 }
37 if (document.getElementById( " t " + id))
38 {
39 eval ( " t " + id).style.display = ' none';
40 document.getElementById( " load_ " + id).style.display = ' none';
41 return;
42 }
43 else
44 {
45 document.getElementById( " load_ " + id).style.display = ' none';
46 }
47 break;
48 }
49 case " false " :
50 {
51 with (dir_id)
52 {
53 innerText = " - " ;
54 open = " true " ;
55 className = ' diropen';
56 }
57
58 document.getElementById( " load_ " + id).style.display = ' ';
59
60 if (document.getElementById( " t " + id))
61 {
62 eval ( " t " + id).style.display = ' ';
63 eval ( " load_ " + id).style.display = ' none';
64 return;
65 }
66 else
67 {
68 document.frames[ ' hifm'].location.replace("subtree.asp?id="+id);
69 }
70 break;
71 }
72 default:dir_id.innerText = " . " ;dir_id.className = ' dirNode';return;
73 }
74
75 }
76
77 function ArrToHtml(ArrNode,nodeid)
78 {
79 // 输出到页面
80 varnode_html = ' <tableid="t'+nodeid+'"width="100%"border="0"style="position:relative;left:18px;"cellspacing="0"cellpadding="0">';
81
82 varstr,opened,cls
83 for (vari = 0 ;i < ArrNode.length;i ++ )
84 {
85 if (ArrNode[i].iChildren == 0 )
86 {
87 str = ' .';
88 opened = ' no';
89 cls = ' dirNode';
90 }
91 else
92 {
93 str = ' +';
94 opened = ' false';
95 cls = ' dirclose';
96 }
97
98 node_html += ' <tr><tdid="node'+ArrNode[i].id+'"class="td_node"valign="top"><spanclass="'+cls+'"id="dir'+ArrNode[i].id+'"οnclick="expand('+ArrNode[i].id+')"open="'+opened+'">'+str+'</span><spanclass="node"id="s'+ArrNode[i].id+'"οnclick="expand('+ArrNode[i].id+')"title="'+ArrNode[i].Content+'"href="'+ArrNode[i].strLink+'">'+ArrNode[i].Content+'</span></td></tr>';
99
100 if (ArrNode[i].iChildren > 0 )
101 {
102 node_html += ' <trid="load_'+ArrNode[i].id+'"style="display:none"><tdclass="td_node"><tableborder="0"cellspacing="0"cellpadding="0"style="position:relative;left:18;top:0px"><tr><tdclass="td_node"><spanclass="dirNode">.</span><spanclass="load">Loading</span></td></tr></table></td></tr>';
103 }
104 }
105
106 node_html += ' </table>';
107 if (document.getElementById( " load_ " + nodeid))
108 {
109 document.getElementById( " load_ " + nodeid).style.display = " none " ;
110 document.getElementById( " node " + nodeid).innerHTML += node_html;
111 vard = new Date ();
112 d2 = d.valueOf();
113 message.innerHTML = " 耗时: " + (d2 - d1) + " ms " ;
114 }
115 }
116 -->
117 </ script >
118 </ head >
119
120 < bodytopmargin = " 0 " leftmargin = " 0 " scroll = " yes " >
121 < %
122 Dim conn,rs
123 Dim s,open,cls
124 On Error Resume Next
125 Set conn = Server. CreateObject ( " ADODB.Connection " )
126 conn.Open " Provider=Microsoft.Jet.OLEDB.4.0;DataSource= " & Server.mappath( " Tree.mdb " ) & " ;PersistSecurityInfo=False"
127 Set rs = Server. CreateObject ( " ADODB.Recordset " )
128
129 rs.Open " select*,(selectcount(*)fromdeeptreewhereparentid=T.id)aschildrenfromdeeptreeTwhereparentid=0orderbyparentid " ,conn, 1 , 3
130 % >
131 < divid = " message " style = " height:20px " align = " center " > </ div >
132 < divalign = " center " >
133 < center >
134 < tableborder = " 0 " width = " 100% " cellspacing = " 0 " cellpadding = " 0 " height = " 100% " bgcolor = " #F2F2F2 " >
135 < tr >
136 < tdwidth = " 260 " valign = " top " align = " left " >
137 < divid = " treedir " style = " overflow:auto;width:30%;height:100%; " >
138 < tableborder = " 0 " cellspacing = " 0 " cellpadding = " 0 " style = " position:relative;left:18px;top:20px; " width = " 100% " >
139 < %
140 Do While Not rs.EOF
141 If rs( " children " ) = 0 Then
142 s = " ."
143 open = " no"
144 cls = " dirNode"
145 Else
146 s = " +"
147 open = " false"
148 cls = " dirclose"
149 End If
150 % >
151 < tr >
152 < tdid = " node<%=rs( " id " )%> " class = " td_node " valign = " top " >< spanclass = " <%=cls%> " id = " dir<%=rs( " id " )%> " onclick = " expand(<%=rs( " id " )%>) " open = " <%=open%> " >< % = s% ></ span >< spanclass = " node " id = " s<%=rs( " id " )%> " onclick = " expand(<%=rs( " id " )%>) " title = " <%=Trim(rs( " content " ))%> " href = " <%=Trim(rs( " link " ))%> " >< % = rs( " content " )% ></ span >
153 </ td >
154 </ tr >
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值