太难找了,帖到这里:
http://wiki.github.com/collectiveidea/awesome_nested_set/awesome-nested-set-cheat-sheet
Installation
Install as a plugin:
script/plugin install git://github.com/collectiveidea/awesome_nested_set.git
Usage
To make use of awesome_nested_set, your model needs to have 3 fields: lft,
rgt, and parent_id:
class CreateCategories < ActiveRecord::Migration
def self.up
create_table :categories do |t|
t.string :name
t.integer :parent_id
t.integer :lft
t.integer :rgt
end
end
def self.down
drop_table :categories
end
end
Enable the nested set functionality by declaring acts_as_nested_set on your
model
class Category < ActiveRecord::Base
acts_as_nested_set
end
Run `rake rdoc` to generate the API docs and see
CollectiveIdea::Acts::NestedSet::SingletonMethods for more info.
View Helper
The view helper is called #nested_set_options.
Example usage:
<%= f.select :parent_id, nested_set_options(Category, @category) {|i| "#{'-' * i.level} #{i.name}" } %>
<%= select_tag 'parent_id', options_for_select(nested_set_options(Category) {|i| "#{'-' * i.level} #{i.name}" } ) %>
See CollectiveIdea::Acts::NestedSet::Helper for more information about the
helpers.
Basic Usage
- Create a root node:
science = Category.create!(:name => ‘Science’)
- Put a new thing inside this root node:
physics = Category.create!(:name => ‘Physics’) physics.move_to_child_of(science)
- Put another inside this “physics” node:
gravity = Category.create!(:name => ‘Gravity’) gravity.move_to_child_of(physics)
- Reload your root node: @science.reload!
Now you should have something that resembles this: + science |__ physics |____ gravity
Accessing the data:
Class methods:
|
|
Category.root
|
the first root node |
Category.roots
|
all root nodes |
Instance methods
|
|
my_cat.root
|
root for this node. |
my_cat.level
|
the level of this object in the tree. root = 0 |
my_cat.parent
|
the node’s immediate parent |
my_cat.children
|
array of immediate children (just those in the next level). |
my_cat.ancestors
|
array of all parents, parents’ parents, etc, excluding self. |
my_cat.self_and_ancestors
|
array of all parents, parents’ parents, etc, including self. |
my_cat.siblings
|
array of brothers and sisters (all at that level), excluding self. |
my_cat.self_and_siblings
|
array of brothers and sisters (all at that level), including self. |
my_cat.descendants
|
array of all children, childrens’ children, etc., excluding self. |
my_cat.self_and_descendants
|
array of all children, childrens’ children, etc., including self. |
my_cat.leaves
|
array of all descendants that have no children. |
Instance methods: Tests
|
(these don’t need to hit the DB to respond) |
my_cat.root?
|
true if this is a root node |
my_cat.child?
|
true if this is a child node. It has a parent. |
my_cat.is_ancestor_of?(obj)
|
true if nested by any obj |
my_cat.is_or_is_ancestor_of?(obj)
|
true if nested by any obj or self is obj |
my_cat.is_descendent_of?(obj)
|
true if self is nested under obj |
my_cat.is_or_is_descendent_of?(obj)
|
true if self is nested under obj or self is obj |
my_cat.leaf?
|
true if this is a leaf node. It has no children
|
分享到:
相关推荐
awesome-ctf-cheatsheet:CTF备忘单
安装 go get github.com/griffinqiu/go-nested-set用法定义模型您必须使用nestedset Stuct标记来定义Gorm模型,如下所示: 支持结构标签: id -int64-节点的主键parent_id -sql.NullInt64-ParentID列,null为根lft...
要使用awesome_nested_set您的模型需要具有3个字段: lft , rgt和parent_id 。 这些字段的名称是可配置的。 您还可以具有可选字段: depth和children_count 。 这些字段是可配置的。 请注意, c
KubeOps Kubernetes秘籍 这是基于Kubernetes API 1.19版本的Kubernetes备忘单。 Facebook的:YouTube:版权 这项工作是根据。创建对象名称命令建立资源kubectl apply -f ./ <file> .yaml 从多个文件创建kubectl ...
适用于 Android 的 Font Awesome 备忘单 适用于 Android 的完整 Font Awesome 4.3.0 图标参考。 如何使用: 将fontawesome.xml上传到res/values文件夹。 在任何元素上设置文本: <button android:id="@+id/FOO...
从 FontAwesome Cheatsheet 页面自动创建 SVG 以用于 Inkscape 和 Adobe Illustrator 转到: : 打开浏览器控制台 + 粘贴代码 或者,您可以创建一个书签,对其进行编辑并粘贴 bookmarklet.js 的内容,这样您只...
这个"bootstrap_cheatsheet"存储库是专门为学习Bootstrap 4而创建的,它包含了各种组件、工具和最佳实践,帮助开发者迅速掌握这个框架。同时,由于提到了Git工作流程,这个项目也提供了关于版本控制和协作的基础知识...
这个宝石取决于 CollectiveIdea 的 Awesome Nested Set gem。 如果安装此 gem 时尚未存在,则会安装它。 你可以在 GitHub 上的上找到这个 gem 安装 在您的 Gemfile 中,添加: gem 'acts_as_commentable_with_...
解压后,我们可以看到两个主要文件:`Font Awesome Cheatsheet.png`和`fontawesome-webfont.ttf`。`Font Awesome Cheatsheet.png`是一份包含Font Awesome所有图标的参考表,方便开发者查找和选择合适的图标。而`font...
我在网上找到了一个网站,该网站直接使用Javascript从https://fontawesome.com/cheatsheet提取了代码。 我尝试过,但似乎网站已更改。 我很快决定使用C#.Net控制台应用程序和HTMLAgility Nuget包来创建我的。 ...
cheatsheet.dennyzhang.com:通过CheatSheets应用最佳实践
数据表 生成您自己的备忘单作为文档集!... introduction 'My *awesome* cheatsheet for tmux' # A cheatsheet must consist of categories category do id 'windows' # must be unique and is used as
http://fortawesome.github.io/Font-Awesome/cheatsheet/网页转化成的pdf 看到对应的图标就可以得到相应的glyph数字哦。简单易用,转化成pdf随时可以使用的哦 可以参照 ...
"Font Awesome Cheatsheet.pdf"是一个重要的参考资料,它列出了4.7.0版本中所有可用的图标以及对应的CSS类名。开发者可以借助此表快速查找并使用所需的图标,极大地提高了工作效率。 在"font-awesome-4.7.0"压缩包...
与和awesome_nested_set一起使用。 奖励功能: 对带有rails_admin_toggleable的已enabled列的特殊情况支持 cover和image栏的特殊情况支持 安装 将此行添加到应用程序的Gemfile中: gem 'rails_admin_nested_set...
开发工具 fontawesome-webfont.ttf开发工具 fontawesome-webfont.ttf开发工具 fontawesome-webfont.ttf开发工具 fontawesome-webfont.ttf开发工具 fontawesome-webfont.ttf开发工具 fontawesome-webfont.ttf开发工具...
开发工具 FontAwesome开发工具 FontAwesome开发工具 FontAwesome开发工具 FontAwesome开发工具 FontAwesome开发工具 FontAwesome开发工具 FontAwesome开发工具 FontAwesome开发工具 FontAwesome开发工具 FontAwesome...
开发工具 fontawesome-webfont.eot开发工具 fontawesome-webfont.eot开发工具 fontawesome-webfont.eot开发工具 fontawesome-webfont.eot开发工具 fontawesome-webfont.eot开发工具 fontawesome-webfont.eot开发工具...
Fontawesome 6.1 Pro是一款深受开发者和设计师喜爱的图标库,它提供了丰富的矢量图标、字体和CSS工具,使得在网页设计和开发过程中轻松添加和定制图标成为可能。这个专业版包含了更多高级特性和图标,旨在提升用户...
内含fontawesome-pro-5.14.0、FontAwesome v4.7、fontawesome-free-6.5.1三个版本