您好我在这里看过这篇文章并且我已经尝试了但是在父菜单显示正确但子菜单根本没有显示之后,我做了断点检查问题,它说子菜单长度= 0,我无法弄清楚为什么请帮我们检查一下这段代码。
Private Function GenerateUL(menu As DataRow(), table As DataTable, sb As StringBuilder) As String
If menu.Length > 0 Then
For Each dr As DataRow In menu
'Dim handler As String = dr("Handler").ToString()
'Dim menuText As String = dr("MENU").ToString()
Dim tran_Cd = dr("tran_Cd").ToString()
Dim menu_Nm = dr("menu_Nm").ToString()
Dim menu_Descr = dr("menu_Descr").ToString()
Dim url = dr("url").ToString()
Dim id = System.Convert.ToInt32(dr("ID"))
Dim parent_ID = System.Convert.ToInt32(dr("parent_ID"))
Dim proj_Nm = dr("proj_Nm").ToString()
Dim search_Vw = dr("search_Vw").ToString()
Dim sort_Seq = dr("sort_Seq").ToString()
Dim controller = dr("controller").ToString()
Dim line As String = [String].Format("<li><a href=""{0}"">{1}</a>", controller, menu_Descr)
sb.Append("</li>")
Dim subMenu As DataRow() = table.[Select]([String].Format("parent_id = {0}", id))
'Dim subMenu As DataRow() = table.[Select]("parent_id = 0")
If subMenu.Length > 0 AndAlso Not id.Equals(parent_ID) Then
Dim subMenuBuilder = New StringBuilder()
sb.Append(GenerateUL(subMenu, table, subMenuBuilder))
Dim Subline As String = [String].Format("<li><a href=""{0}"">{1}</a>", controller, menu_Descr)
sb.Append("</li>")
End If
Next
End If
Return sb.ToString()
End Function
这是我的表:
> ID MENU_DESCR PARENT_ID
> 16 Implementor Group 17
> 17 Group Maintenance 0
> 1 User Maintenance 0
> 2 Create 1
> 4 Delete 1
> 6 Change Password 1
> 5 Role Maintenance 0
> 11 List View 1
> 8 Approval Dashboard 0
> 12 Script Maintenance 0
> 7 Change 1
> 10 Approver Group 17
> 14 Template Maintenance 0
> 15 Submitter Group 17