我有需要显示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
方法对象为我转储整个树结构,虽然这有效。