如何制作无限动态菜单系统?
我有一个 wiki 类型的应用程序,管理员可以在其中创建页面。每个页面都必须放入菜单系统中,该系统由管理员即时创建。
Menu Heading
L Subheading
L Page1
但是,菜单可能有更多页面,例如:
Menu Heading
L Subheading
L Page1
L New Subheading
L Page2
菜单必须易于修改,并且必须有一种方法来订购菜单标题/副标题以及里面的页面。
所以基本上,我需要一个完全动态的菜单,不需要任何类型的静态数据。
我有一个当前有效的方法,但我无法控制页面顺序。如果我没有得到很多关于如何去做的回复,我会提出我目前的做事方式(我只是不想将想法放入你的脑海中,我正在寻找一种新的方法)
谢谢
编辑:谢谢所有这些都是为了您的答复,但是,我认为情况比我现在可以用言语表达的要复杂一些。让我想一个更好的方式来问我的问题......我可能会在下周重新发布
I have a wiki-type app where an administrator can create pages. Each page must be put into the menu system, which is created on-the-fly by the administrator
Menu Heading
L Subheading
L Page1
However, there may be more pages for the menu such as:
Menu Heading
L Subheading
L Page1
L New Subheading
L Page2
The menu must be easy to modify and there must be a way to order the headings/subheadings as well as the pages inside.
so basically, an entirely dynamic menu is what i need NO STATIC DATA OF ANY KIND.
I've got a current method that works except i am unable to control page order. If i dont get many responses how to go about it, i will put up my current way of doing things (i just don't want to put ideas into your head, i'm looking for a fresh approach)
Thanks
EDIT: Thank you all for your responses, however, I think the situation is a bit more complex than i can put into words right now. Let me think of a better way to ask my question... I'll repost probably next week
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我们将使用 分层架构,为每个项目添加排序顺序,然后就是这样。
Well use a hierarchical schema, add a sort order to each item and that's it.
完成具有父级的系统的最简单方法 ->孩子->孩子……关系将是一棵树。您使用的设置可能如下所示:
这将是数据库:
您可以通过两个简单的查询获得完整的结构,如下所示:
当您添加子项时,您必须扩大父级 tree_left 和 right 之间的间隙。当你在子项、子项等中时,你应该递归地执行此操作。如果我没有记错的话,这可以在 1 个查询中完成。
尝试在网络上搜索更详细的示例,这是一种称为嵌套集的常用树结构。
The easiest way to accomplishing a system which has parent -> child -> child... relations would be a tree. Where you use a setup which could look like this:
This would be the database for:
You can get the full structure in 2 easy querys like so:
When you add children you must enlarge the gap between your parent tree_left and right. you should do this recursively when your in sub, sub items etc. Which can be done in 1 query if i'm not mistaking.
Try and search on the web for more detailed exampled this is a common used tree structure called nested set.
结构如下的表应该可以做到这一点。
等。
插入项目应该只需要简单的重新排序。
A table structured as follows should do it.
Etc..
Inserting items should just require a simple reorder.
您正在寻找的称为递归,这里是相关问题示例,我还建议阅读这篇文章。
What you are looking for, is called recursion, here is related question example, also I would recommend to read this article.
您到底想知道什么?
如果您对结构感兴趣,请查看这篇关于分层数据的文章在 MySQL 网站上。
Exactly what are you wanting to know?
If you are interested in structure, check out this article on hierarchical data on the MySQL website.