Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the infinite level classification tree structure by ajax+asp

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "how to realize the infinite level classification tree structure of ajax+asp". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "ajax+asp how to achieve unlimited classification tree structure" it!

The copy code is as follows:

0 then

Dim rsPrevOrderID

'get the OrderID of the last column at the same level as this column

Set rsPrevOrderID=conn.execute ("select Max (OrderID) From ArticleClass where ParentID=" & ParentID)

PrevOrderID=rsPrevOrderID (0)

'get the maximum OrderID of the subcolumn of the same parent column but larger than the series of this column. If it is larger than the previous value, use this value instead.

Set rsPrevOrderID=conn.execute ("select Max (OrderID) From ArticleClass where ParentPath like'" & ParentPath & ",%'")

If (not (rsPrevOrderID.bof and rsPrevOrderID.eof)) then

If not IsNull (rsPrevOrderID (0)) then

If rsPrevOrderID (0) > prevOrderID then

PrevOrderID=rsPrevOrderID (0)

End if

End if

End if

Set rsPrevOrderID=nothing

End if

NOrderID=prevOrderID+1

Else

NOrderID=0

SParentPath= "0"

NDepth=0

End if

Set rs=nothing

NChild=0

Sql= "insert into ArticleClass (ClassID,ClassName,ParentID,ParentPath,Depth,RootID,Child,OrderID,FilePath) values (" & nClassID & ",'& sClassName &", "& nParentID &",'& sParentPath & "'," & nDepth & "," & nRootID & "," & nChild & "," & nOrderID & ",'" & sFilePath & ")"

Conn.execute (sql)

If ParentID > 0 then

'update the number of child columns of its parent class

Conn.execute ("update ArticleClass set child=child+1 where ClassID=" & nParentID)

'Update the sorting of this column and the sorting order number of the column that is larger than this need and is also under this classification

If prevOrderID "" then

Conn.execute ("update ArticleClass set OrderID=OrderID+1 where rootid=" & nRootid & "and OrderID >" & prevOrderID & "and ClassID" & nClassID)

End if

End if

End Sub

The Public Function FEditCheck () 'category modifies the check function. If 0 is passed, 1 means an error has occurred. Exit the function when an error occurs, and write the error information to the error variable ErrorStr.

Dim temprs

FEditCheck=0

If nClassID= "" then "category id is empty

FEditCheck=1

ErrorStr= "Category id cannot be empty!"

Exit Function

Else

If sClassName= "" then 'class name is empty

FEditCheck=1

ErrorStr= "Class name cannot be empty!"

Exit Function

Else

If nParentID0 then

Set temprs=conn.execute ("select ClassID From ArticleClass where ClassID=" & nParentID) 'parent category does not exist

If temprs.eof then

FAddCheck=1

ErrorStr= "belongs to a category that does not exist or has been deleted!"

Exit Function

Else

Set rs=conn.execute ("select ClassID from ArticleClass where ClassName='" & sClassName & "'and ClassID" & nClassID & "and ParentID=" & nParentID)

Duplicate if not rs.eof then 'class name

FEditCheck=1

ErrorStr= "duplicate class name!"

Exit Function

End if

Set rs=nothing

End if

Set temprs=nothing

End if

End if

End if

End Function

Public Sub SEdit () 'category modification

Sql= "update ArticleClass set ClassName='" & sClassName & ", FilePath='" & sFilePath & "where ClassID=" & nClassID

Conn.execute (sql)

End Sub

The Public Function FDeleteCheck () 'category deletes the check function. If 0 is passed, 1 means an error has occurred. Exit the function when an error occurs, and write the error information to the error variable ErrorStr.

FDeleteCheck=0 'here delete the code that is not cascaded to delete the article. When deleting, it should be cascaded deleted.

If nClassID= "" then

FDeleteCheck=1

ErrorStr= "the category id to be deleted cannot be empty!"

Exit Function

Else

Set rs=conn.execute ("select Child from ArticleClass where ClassID=" & nClassID)

If rs.bof and rs.eof then

FDeleteCheck=1

ErrorStr= "category does not exist or has been deleted!"

Exit Function

Else

If trim (rs ("Child")) > 0 then

FDeleteCheck=1

ErrorStr= "this category contains subcategories, please delete its subcategories before deleting this category!"

Exit Function

End if

End if

End if

End Function

Public Sub SDelete ()

If nDepth > 0 then 'modify the number of children in the parent id

Conn.execute ("update ArticleClass set child=child-1 where child > 0 and ClassID=" & nParentID)

End if

Sql= "delete from ArticleClass where ClassID=" & nClassID

Conn.execute (sql)

End Sub

Public Function FErrStr ()

FErrStr=ErrorStr

End Function

End Class

% >

Core js code

The copy code is as follows:

Var xmlHttp; / / define a global variable

Var currentID=1;// setting currently selects ID. If this ID does not exist, a js error will occur.

/ / Category display main function

/ / id at the layer where the cid-- subcategory resides

/ / id-Category id

/ / pid-- [+] and [-] icons id

/ / fid-- category icon id

Function DivDisplay (cid,id,pid,fid)

{

If (GetId (cid) .style.display = ='') / / Icon display control when subcategories are not displayed

{

GetId (cid). Style.display='none'

GetId (pid). Src = 'images/closed.gif'

GetId (fid). Src = 'images/folder.gif'

}

Else / / actions when expanding subcategories

{

GetId (cid) .style.display =''

GetId (pid). Src = 'images/opened.gif'

GetId (fid). Src = 'images/folderopen.gif'

If (GetId (cid) [xss_clean] = =''| | GetId (cid) [xss_clean] = 'submitting data...')

{

GetId (cid) [xss_clean] =''

ShowChild (cid,id); / / call the display subcategory function

}

}

}

/ / same as the previous function, only in the last category

Function DivDisplay2 (cid,id,pid,fid)

{

If (GetId (cid) .style.display = ='')

{

GetId (cid). Style.display='none'

GetId (pid). Src = 'images/lastclosed.gif'

GetId (fid). Src = 'images/folder.gif'

}

Else

{

GetId (cid) .style.display =''

GetId (pid). Src = 'images/lastopen.gif'

GetId (fid). Src = 'images/folderopen.gif'

If (GetId (cid) [xss_clean] = =''| | GetId (cid) [xss_clean] = 'submitting data...')

{

GetId (cid) [xss_clean] =''

ShowChild (cid,id)

}

}

}

/ / Category add function

/ / id-- category id

Function ClassAdd (id) {

If (GetId ("p" + id) .src.indexOf ("last") > 0) {/ / add to the last category

If (! GetId ("p" + id) .onclick) {

GetId ("p" + id). Onclick=function () {DivDisplay2 ("c" + id,id, "p" + id, "f" + id);}; / / add click events to [+] and [-]

GetId ("s" + id). Ondblclick=function () {DivDisplay2 ("c" + id,id, "p" + id, "f" + id);}; / / add a double-click event to the span that displays category text

GetId ("p" + id). Src = 'images/lastopen.gif'

}

}

Else {

If (! GetId ("p" + id) .onclick) {/ / is not an add operation for the last category

GetId ("p" + id). Onclick=function () {DivDisplay ("c" + id,id, "p" + id, "f" + id);}

GetId ("s" + id). Ondblclick=function () {DivDisplay ("c" + id,id, "p" + id, "f" + id);}

GetId ("p" + id). Src = 'images/opened.gif'

}

}

GetId ("c" + id) .style.display =''

ShowChild ("c" + id,id)

}

/ / Category modification function

Function ClassEdit (id,classname) {

GetId ("s" + id) [xss_clean] = classname

}

/ / Delete function for categories with multiple subcategories

Function ClassDel (id) {

ShowChild ("c" + id,id)

CurrentSelect (currentID,id)

BrowseRight (id)

}

/ / Delete function of a category with only one subcategory

Function ClassDel1 (id) {

If (GetId ("p" + id) .src.indexOf ("last") > 0) {/ / when the category is the last category of the current category

GetId ("p" + id) .style.cursor = "cursor"; / / sets the mouse over style of the icon

GetId ("p" + id) .onclick=function () {}; / / because only one subcategory is deleted and there is no subcategory, change the icon click event to an empty function

GetId ("s" + id). Ondblclick=function () {}; / / ditto

GetId ("p" + id) .src = 'images/lastnochild.gif'; / / icon settings

}

Else {

GetId ("p" + id) .style.cursor = "cursor"; / / deletion operation that is not the last category

GetId ("p" + id). Onclick=function () {}

GetId ("s" + id). Ondblclick=function () {}

GetId ("p" + id). Src = 'images/nofollow2.gif'; / / the icon settings here are not the same as before

}

ShowChild ("c" + id,id)

CurrentSelect (currentID,id)

BrowseRight (id)

}

/ / pass parameters to the right frame

Function BrowseRight (id) {

CurrentSelect (currentID,id)

Top.ContentFrame.location= ".. / ArticleMain.asp?ClassID=" + id

}

/ / A function that sets the selected status of a category

Function CurrentSelect (oldid,newid) {

CurrentID=newid

Document.getElementById ("s" + oldid) .style.backgroundColor = "white"

Document.getElementById ("s" + currentID) .style.backgroundColor = "# C0C0E9"

}

/ / create a XMLHttpRequest object

Function CreateXMLHttpRequest ()

{

If (window.ActiveXObject)

{

XmlHttp = new ActiveXObject ("Microsoft.XMLHTTP")

}

Else

{

XmlHttp = new XMLHttpRequest ()

}

}

/ / Ajax handler function

/ / id, layer id

/ / rid, id of the data in the table

Function ShowChild (cid,id)

{

CreateXMLHttpRequest ()

If (xmlHttp)

{

XmlHttp.open ('POST','child.asp',true)

XmlHttp.setRequestHeader ('Content-Type','application/x-www-form-urlencoded')

Var SendData = 'id='+id

XmlHttp.send (SendData)

XmlHttp.onreadystatechange=function ()

{

If (xmlHttp.readyState==4)

{

If (xmlHttp.status==200)

{

GetId (cid) [xss_clean] = xmlHttp.responseText

}

Else

{

GetId (cid) [xss_clean] = 'error:' + xmlHttp.statusText

}

}

Else

{

GetId (cid) [xss_clean] = "submitting data..."

}

}

}

Else

{

GetId (cid) [xss_clean] = 'Sorry, your browser does not support XMLHttpRequest, please use IE6 above!'

}

}

/ / get the page object

/ / id, layer id

Function GetId (id)

{

Return document.getElementById (id)

}

At this point, I believe you have a deeper understanding of "how to achieve the infinite level classification tree structure of ajax+asp". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report