Ruby on Rails - 很棒的嵌套集插件 [英] Ruby on Rails - Awesome nested set plugin

查看:38
本文介绍了Ruby on Rails - 很棒的嵌套集插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用这个插件时,有没有一种简单的方法可以显示整个嵌套集?我想要做的是显示一个根节点的无序列表,每个子节点中还有另一个无序列表,其中还包含子节点等等?

Is there a simple way to display the entire nested set when using this plugin? What I would like to do is display an unordered list of root nodes with another unordered list inside each child that also contains children and so on?

感谢任何建议.

谢谢.

推荐答案

使用 your_model.children 将需要在每次遇到数据库时再次命中,这是不可取的.

Using your_model.children will require another hit on the database each time it is encountered which is not preferable.

我创建了一个帮助器,它帮助生成嵌套的 ul 和 li 标签,并且只有一个数据库命中.您可以根据自己的需要修改此帮助程序:

I have created a helper which helps generate the nested ul and li tags with only one database hit. You can modify this helper for your own needs:

https://github.com/collectiveidea/awesome_nested_set/wiki/How-to-generate-nested-unordered-list-tags-with-one-DB-hit

这篇关于Ruby on Rails - 很棒的嵌套集插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆