使用 ASP.NET、JQuery 和 Suckerfish 构建数据库驱动的菜单
- 作者: 给LZ来包辣条
- 来源: 51数据库
- 2022-10-20
问题描述
我正在尝试使用 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.
- C#通过fleck实现wss协议的WebSocket多人Web实时聊天(附源码)
- 团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
- 使用 MSBuild.exe 在发布模式下构建 C# 解决方案
- 当我发布 Web 应用程序时,AfterPublish 脚本不运行
- 构建时 T4 转换的产品仅在下一个构建中使用
- ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
- 新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
- 如何将条件编译符号(DefineConstants)传递给 msbuild
- MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
- NuGet 包还原找不到包,没有源
