使用 ASP.NET、JQuery 和 Suckerfish 构建数据库驱动的菜单 [英] Building a database driven menu with ASP.NET, JQuery and Suckerfish

查看:16
本文介绍了使用 ASP.NET、JQuery 和 Suckerfish 构建数据库驱动的菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Suckerfish css 菜单和 Jquery 从表创建菜单.我使用它作为我的参考:Suckerfish menu with ASP.NET 和 JQuery,我让它使用手动提供的链接(很像文章中的那样).

I'm attempting at creating a menu from a table using the Suckerfish css menu and Jquery. I'm using this as my reference: Suckerfish menu with ASP.NET and JQuery and I have it working with manually supplied links (much like in the article).

我遇到问题的地方是编写递归函数以从数据库中获取菜单项并在适当的层次结构中创建新菜单项.我的数据库表看起来像这样:

Where I'm having issues is writing the recursive function to get the menu items from the database and create the new menu items in the proper hierarchy. My database table looks like so:

餐桌菜单

菜单ID家长编号关联文字

MenuID ParentID Link Text

这个想法是,如果一个项目是父级项目,MenuID 和 ParentID 是相同的,如果它是一个子项,它将在 ParentID 字段中具有它的父项的 MenuID.我需要创建一个函数,该函数可以通过并为父母找到所有孩子(可能是几个级别)并让它替换如下手动条目:

The idea being that if an item is a parent-level item the MenuID and ParentID are the same, if it's a child it will have the MenuID of it's parent in the ParentID field. I'm needing to create a function that can go through and find all of the children for the parents (could be a few levels) and have it replace manual entries like this:

        Dim Foo As New MenuItem("#", "Foo", Me)
        Items.Add(Foo)
        Foo.Items.Add(New MenuItem("#", "1", Me))
        Foo.Items.Add(New MenuItem("#", "2", Me))
        Foo.Items.Add(New MenuItem("#", "3", Me))
        Foo.Items.Add(New MenuItem("#", "4", Me))

如有必要,我愿意更改数据库表结构,并且基本上会做任何其他事情来实现这一目标.

I'm open to changing the database table structure if necessary and basically doing anything else to get this going.

感谢您的任何意见,非常感谢.

Thanks for any input, it's much appreciated.

推荐答案

这种表示分层数据的方法对于人类来说很容易理解,但很难从中提取数据,因为它需要递归来提取完整​​的层次结构.某些 SQL 版本具有可以为您执行此操作的命令,但这就是幕后发生的事情.

That method of representing hierarchical data is easy to understand for humans but difficult to extract data from, because it requires recursion to extract the full hierarchy. Some flavors of SQL have commands that will do this for you, but that is what is going on behind the scenes.

我建议你阅读更多的树和;SQL 中的层次结构,并使用它解释的具体化路径方法重构您的架构.它很容易查询并且扩展性非常好.

I suggest you read More Trees & Hierarchies in SQL, and restructure your schema using the materialized path method that it explains. It is easy to query against and scales really well.

这篇关于使用 ASP.NET、JQuery 和 Suckerfish 构建数据库驱动的菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆