如何设置树结构子节点的顺序
我在 CMS 应用程序中有一个页面的树形表示。 我了解如何将树持久保存在数据库中。 但是,我没有一个好的方法来:
A)对特定父页面下的子页面重新排序。
B) 提供允许用户更改顺序的 UI 实现。
有什么建议么?
I have a tree representation of pages in a CMS application. I understand how to persist the tree in the database. However, I don't have a good way to:
A) Reorder subpages under a particular parent page.
B) Provide a UI implementation that allows the user to change the order.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
A)我有一个类似的 CMS 应用程序,我在特定树的页面中存储序号值,并根据该值进行排序 - 因为我的很多页面出现在完全不同的站点中,所以我必须针对页面/树维护序号组合。
B)我也想要一个更好的方法来做到这一点。 目前,他们单击树视图中的节点,在主页面屏幕中,他们可以移动页面。 我尝试过使用 java 脚本和其他解决方案进行拖放,但如果没有大量的手动操作,我的用户永远无法使用它。 我会对对此的回应感兴趣。
A) I have a similar CMS app and I store an ordinal value with the page for a particular tree and sort on this value -- because lots of my pages appear in completely different sites I have to maintain the ordinal number against a page / tree combination.
B) I too would like a better way to do this. Currently they click on the node in the treeview and in the main page screen they can move the page around. I've tried drag and drop with java script and other solutions but my users could never work with it without lots of hand holding. I'll be interested in the responses to this one.
更改顺序本身需要您将某种顺序与数据库中的每个页面一起存储。 当前的最高/最低值 +/- 1 可能是一个很好的起点。 一旦你在那里进行了排序,重新排序就变成了交换两个值或将一页的值更改为其他两个值之间的情况(我猜你可以使用浮点数,但如果你将其拆分太多,则可能需要重新编号)次)。
不管怎样,一旦你有了它,你就需要一个用户界面。 我见过一种非常简单的“将其与上面/下面的交换”方法,可以是简单的 Web 链接或 AJAX 调用。 您还可以向用户呈现所有页面值,并要求他们根据需要重新编号。 如果您想变得更奇特,JavaScript 拖放可能是一个不错的方法。 我使用过 ExtJS 和 Mootools 作为此类领域的框架。 如果你不需要所有的 Extjs 小部件,我会说将来远离它,看看像 Mootools 动态可排序演示。
Changing the order itself will require you store some sort of ordering along with each page in the database. Just the current highest / lowest value +/- 1 would probably be a fine starting point. Once you've got that ordering in there, reordering becomes a case of swapping two values or changing the value for one page to be between two others (you could use floats I guess, but you may need to renumber if you split it too many times).
Anyway, once you've got that, you need a UI. I've seen a very simple 'swap this with the one above/below' approach which can be a simple web link or an AJAX call. You could also present all the page values to the user and ask them to renumber them as they see fit. If you want to get fancy, JavaScript drag and drop might be a good approach. I've used ExtJS and Mootools as frameworks in this kind of area. If you don't need all the Extjs widgets, I'd say well away from it in future, and look at something like the Mootools Dynamic Sortables demo.