多级项目符号实施
在 php 中实现多级列表/项目符号的最佳方法是什么?
我想要实现的是一个采用简短短语并将它们分类到各个部分的系统。然而,同时,我希望每个部分都是可折叠的,并且能够在其中包含子部分。
例如: 第 10 节
第 10.X 节
第 10.XX 节
我正在考虑将每个子层作为一个数组,但我意识到我在很多地方都看到了相同类型的可折叠性,而且它们似乎都很相似。也许已经有一个包或库可以做到这一点?如果有,我用于保存每个条目的数据结构应该如何构建?
What is the best way of implementing multi-level lists/bullets in php?
What I'm trying to implement is a system to take in short phrases, and categorize them within sections. However, at the same time, I would like to have each section to be collapsible and capable of having sub-sections within them.
For Example:
Section 10
Section 10.X
Section 10.X.X
I was thinking of having each sub-layer as an array, but I realize that I've seen the same type of collapsibility in many places, and they all seem to be similar. Maybe there already is a package or library that does this? And if there is, how should my data-structure for keeping each entry be structured?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的项目符号是用 HTML 完成的,因为 PHP 仅生成 HTML 代码。考虑使用嵌套的
标签。
崩溃很可能是 JavaScript 造成的。 (虽然我想知道 CSS :active psuedoclass 是否可以在支持的浏览器中工作......)
关于该包,我不确定。您本质上需要一个递归列表生成函数。
Your bullets are being done in HTML, as PHP merely generates HTML code. Consider using nested <ul> tags.
The collapsing is most probably going to be javasscript. (Although I wonder if the CSS :active psuedoclass would work in supportive browsers...)
Regarding the package, I'm not sure. You essentially need a recursive list generating function.
对于您提到的那种结构,我认为您需要所谓的 树查看。检查一下如何实施。
屏幕截图:
For the kind of structure you mentioned, i think you need what is know as Tree View. Check it out on how to implement that.
Screenshot:
任何与切换、显示列表、缩进等相关的操作都可以使用 HTML/CSS/Javascript 相对轻松地实现。
在类别表中,您可以创建一个与您的主 ID 匹配的 Parent_id 字段。然后运行循环来显示您的 TLD 以及另一个循环来显示父级中的类别。
Anything to do with toggling, display lists, indenting etc should be achieved relatively easily with HTML/CSS/Javascript.
Inside your category table, you could create a parent_id field which matches to your primary ID. Then run loops to display your TLD as well as another loop to display the categories within the parent.