构建页面站点地图所需的编码概念

发布于 2024-08-23 14:07:33 字数 2436 浏览 8 评论 0原文

我正在使用 VB.NET 3.5 开发 CMS,但我一直坚持一个概念。我有不同的模块,可以做不同的事情,比如所见即所得、联系表格、图片库等……但其中一个正在成为一个挑战,那就是“如何”构建站点地图。

根据记录,我不是在谈论 SEO 站点地图 (XML),而是类似于 Karamasoft(查看 BMW 或 Dell 风格,了解我的拍摄目的)。

我的数据库有以下列,

ID        ParentID        MenuName        Slug            DateUpdated

1         Null            Home            ~/home          01/01/2010
2         Null            About           ~/about         01/01/2010
3         Null            Contact         ~/contact       01/01/2010
4         2               History         ~/history       01/01/2010
5         2               Future          ~/future        01/01/2010
6         3               Jobs            ~/jobs          01/01/2010

我的代码设置方式是将所有相关字段填充到服务器端的一个对象中,然后我可以多次访问该对象,而无需一遍又一遍地访问数据库。

    Public Shared ReadOnly Property Instance() As List(Of NavigationDataItem)
        Get
            Dim n As New List(Of NavigationDataItem)()

            If _Instance Is Nothing Then

                Dim PagesDC As New Dal.icms_PagesDataContext()
                Dim results = PagesDC.icms_Pages_GetPageMenu().ToList

                For Each o As Object In results
                    If o.isHomePage Then
                        n.Add(New NavigationDataItem(o.ID, o.ParentID, o.MenuName, "~/", o.DateUpdated))
                    Else
                        n.Add(New NavigationDataItem(o.ID, o.ParentID, o.MenuName, o.Slug, o.DateUpdated))
                    End If
                Next

                _Instance = n
            Else : n = _Instance
            End If
            Return n
        End Get
    End Property 'Instance

我想做的是将所有没有 ParentID 的记录(即:它们是顶级项目)列在顶部,并将其所有子记录列在下面。

<table>
  <tr>
    <th>Home</th>
    <th>About</th>
    <th>Contact</th>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>History</td>
    <td>Jobs</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>Future</td>
    <td>&nbsp;</td>
  </tr>
</table>

我希望能够动态设置表格列数,这样如果我有 10 个父项并且仅将宽度设置为 5 列,则其余父项将列在下面的另一个表格行中。

我确信一旦我明白了这个问题,我就可以自己构建代码,我只是在寻找如何解决这个问题的“概念”。

另外,我并不是在寻找树视图,因为这基本上就是我现在正在做的事情,而且我真的一点也不喜欢它。

I'm working on a CMS using VB.NET 3.5 and I'm stuck on a concept. I have different modules that do different things like wysiwyg, contact form, image gallery, etc... but one that is becoming a bit of a challenge is wrapping my head around "how" to build a sitemap.

For the record, I am NOT talking about an SEO Sitemap (XML), but rather a visitor sitemap similar to Karamasoft (Check out the BMW or the Dell style for an idea of what I'm shooting for).

My Database has the following columns

ID        ParentID        MenuName        Slug            DateUpdated

1         Null            Home            ~/home          01/01/2010
2         Null            About           ~/about         01/01/2010
3         Null            Contact         ~/contact       01/01/2010
4         2               History         ~/history       01/01/2010
5         2               Future          ~/future        01/01/2010
6         3               Jobs            ~/jobs          01/01/2010

I have my code setup in such a way that I populate all the relevant fields into an Object on the server side that I can then access multiple times without hitting the DB over and over.

    Public Shared ReadOnly Property Instance() As List(Of NavigationDataItem)
        Get
            Dim n As New List(Of NavigationDataItem)()

            If _Instance Is Nothing Then

                Dim PagesDC As New Dal.icms_PagesDataContext()
                Dim results = PagesDC.icms_Pages_GetPageMenu().ToList

                For Each o As Object In results
                    If o.isHomePage Then
                        n.Add(New NavigationDataItem(o.ID, o.ParentID, o.MenuName, "~/", o.DateUpdated))
                    Else
                        n.Add(New NavigationDataItem(o.ID, o.ParentID, o.MenuName, o.Slug, o.DateUpdated))
                    End If
                Next

                _Instance = n
            Else : n = _Instance
            End If
            Return n
        End Get
    End Property 'Instance

What I'm trying to do is have all of the records that have NO ParentID (IE: they are top level items) be listed at the top, and all of it's children listed underneath.

<table>
  <tr>
    <th>Home</th>
    <th>About</th>
    <th>Contact</th>
  </tr>
  <tr>
    <td> </td>
    <td>History</td>
    <td>Jobs</td>
  </tr>
  <tr>
    <td> </td>
    <td>Future</td>
    <td> </td>
  </tr>
</table>

I want to be able to dynamically set the number of table columns, so that if I have 10 Parent items and only set my width to 5 columns, the remaining parent items would be listed in another table row below.

I'm sure I can build the code myself once I wrap my head around this, I'm just looking for a "concept" on how to approach this problem.

Also, I am NOT looking for a Treeview since that's basically what I'm doing now and I really don't love it at all.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

讽刺将军 2024-08-30 14:07:33

您可以使用 DataList 设置列数并仅将其与顶级项目绑定。然后使用一个简单的函数来获取每个主项目的子项目,并使用转发器渲染它们:

<asp:DataList RepeatColumns="5" DataSource="<%#GetParentMenuItems()%>" runat="server">
  <ItemTemplate>
    <h1><%#Container.DataItem.MenuName%></h1>
    <hr />
    <asp:Repeater DataSource="<%#GetChildMenuItems(Container.DataItem.ID)%>" runat="server">
      <ItemTemplate>
        <a href="<%#Container.DataItem.Slug%>"><%#Container.DataItem.MenuName%></a>
        <br />
      </ItemTemplate>
    </asp:Repeater>
  </ItemTemplate>
</asp:DataList>

理想情况下,子项目将是挂在父项上的集合,然后您可以将嵌套的转发器直接绑定到它。然后,您可以创建一个呈现项目的用户控件,然后嵌套自身以呈现任何子项目。

顺便说一句:我认为坚持使用 .NET 站点地图而不是自己制作站点地图会对自己有利。许多方便的控件都在使用它,并且它与 ASP.NET 框架的其余部分很好地集成。 :)

You could use a DataList to set the number of columns and bind that with top level items only. Then use a simple function to get the childitems for each main item and render those with a repeater:

<asp:DataList RepeatColumns="5" DataSource="<%#GetParentMenuItems()%>" runat="server">
  <ItemTemplate>
    <h1><%#Container.DataItem.MenuName%></h1>
    <hr />
    <asp:Repeater DataSource="<%#GetChildMenuItems(Container.DataItem.ID)%>" runat="server">
      <ItemTemplate>
        <a href="<%#Container.DataItem.Slug%>"><%#Container.DataItem.MenuName%></a>
        <br />
      </ItemTemplate>
    </asp:Repeater>
  </ItemTemplate>
</asp:DataList>

Ideally, the child items would be a collection hanging off the parent, then you could bind the nested repeater to that directly. You could then create a user control that renders the items, and then nest itself to render any sub-items.

On a side-note: I think you'll be doing yourself a favor by sticking to the .NET sitemap rather than cooking up your own. Lots of handy controls are using it, and it's nicely integrated with the rest of the ASP.NET framework. :)

救星 2024-08-30 14:07:33

使用 ASP:Table 控件并一次添加一个单元格,当达到所需宽度 (5) 时开始新行

Use an ASP:Table control and add cells one at a time, when you reach your desired width (5) start a new row

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文