【发布时间】:2010-09-20 03:34:48
【问题描述】:
我需要在 HTML 中显示嵌套的集合结构。我正在使用以下部分:
<ul<%= ' id="tree"' if depth == 0 %>>
<% items.each do |item| %>
<li id="node_<%= item.id %>"><a><%= item.name %></a>
<% if item.has_children? %>
<%= render :partial => 'tree_level', :locals => {:items => item.children, :depth => depth + 1} %>
<% end %>
</li>
<% end %>
</ul>
这是获取代码的最佳位置吗?我“觉得”对象上应该有一个 to_html 方法,它为我转储整个树结构,尽管这可行。
【问题讨论】: