acts_as_tree与树状菜单的祖先宝石 [英] acts_as_tree vs ancestry gem for tree menu
问题描述
我想实现树形菜单(树形菜单的简单示例)我正在开发的Rails应用程序。我不确定是使用acts_as_tree还是Ancestry。它似乎更容易使用acts_as_tree实现简单的树形菜单,然而,Ancestry更受欢迎并且定期维护。有人对此有任何想法吗?
I want to implement a tree menu (simple example of tree menu) in a Rails app that I am working on. I am unsure of whether to use acts_as_tree or Ancestry. Its seems that it would be easier to implements a simple tree menu using acts_as_tree, however, Ancestry is more popular and regularly maintained. Does anyone have any thoughts on this?
推荐答案
使用祖先。它具有更强大的查询功能,因为它实现了物化路径模式,相对于实现 adjacency list 。
还有其他选项,例如嵌套集,但物化路径通常是最全面的。
Use ancestry. It has more powerful query capabilities as it implements the materialized path pattern, as opposed to acts_as_tree that implements adjacency list.
There are other options too, like nested set, but materialized path is usually the most comprehensive.
https://communities.bmc.com/communities/docs/ DOC-9902
如果您需要在数据库级别进行预先排序(例如分页树形网格,您要迭代的预加载菜单和缩进/根据树中的深度进行显示),您需要使用递归查询或可嵌套集或嵌套间隔等可排序编码。 (这是如果在内存中排序不是一个选项,它几乎从来没有。)
If you need to sort in preorder at DB level (for example a paginated tree-grid, a preloaded menu that you iterate and indent/dedent according to the depth in tree for displaying) you need to either use a recursive query, or sortable encoding like nested set or nested interval. (That is if sorting in memory is not an option, and it almost never is.)
https://github.com/collectiveidea/awesome_nested_set
https://github.com/ clyfe / acts_as_nested_interval
每个都有起伏。选择适合你的东西。
Each has ups and downs. Choose your what fits you.
这篇关于acts_as_tree与树状菜单的祖先宝石的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!