在我看来,我得到了所有页面
我得到了我所有的页面以及所有的孩子和子孩子。如何得到树形结构如下图:
<% for page in @pages%>
<li id="<%= page.id%>_page">
<div class="link">
#my attributes for the div<
/div>
#here I got the all siblings of that page. But here the structure is of just two
#levels. I need upto n-levels.
<% @childs = page.*descendants* %>
<% if !@childs.nil? && !@childs.empty? %>
<% for child in @childs%>
<ol class="child">
<li id="<%= child.id%>_page">
<div class="link">
#my attributes for the div
</div>
</li>
</ol>
<%end%>
<%end%>
</li>
<%end%>
我正在使用嵌套集并希望以这种方式构建结构:
page1
page 2
page 3
page 3.1
page 3.2
page3.4
...so on to last child
page 4
page 5
....so on to N-levels...