我是新來的鐵軌,我想知道是否有一個簡單的(或不簡單)的方式來縮進DPS的每個孩子?縮進深度第一次搜索(軌道上的紅寶石)的每個孩子?
我有一個叫做「評論」的模型has_many:comments和belongs_to:comment。在我看來,我已經實現了一個DPS顯示每個評論並評論每個評論,對此有何評論每個評論等
我的代碼如下所示:
<div class=feed>
\t <% @comments.each do |comment| %>
\t \t <% if comment.comment_id == nil # display all original comments %>
\t \t \t
\t \t \t <!-- subject -->
\t \t \t <div class="subject">
\t \t \t \t <%= comment.subject %>:
\t \t \t </div>
\t \t \t <!-- create array of replies -->
\t \t \t <% replies = Array.new %> \t
\t \t \t <% replies.push(comment) %>
\t \t \t <% while replies.any? %>
\t \t \t \t <% reply = replies[0] %>
\t \t \t \t <% replies.delete_at(0) %>
\t \t \t \t
\t \t \t \t <!--- name -->
\t \t \t \t <div class="comment">
\t \t \t \t \t <%= User.find(reply.user_id).name %>
\t \t \t \t <!-- comment -->
\t \t \t \t \t <%= reply.body %>
\t \t \t \t \t <% if user_signed_in? %>
\t \t \t \t \t \t <%= link_to "reply", new_comment_comment_path(reply.id) %> \t
\t \t \t \t \t <% end %>
\t \t \t \t </div>
\t \t \t \t <% reply.comments.each do |further_replies| %>
\t \t \t \t \t <% replies.push(further_replies) %>
\t \t \t \t <% end %>
\t \t \t \t <br>
\t \t \t <% end %>
\t \t \t <br>
\t \t <% end %>
\t <% end %>
</div>
我將每個評論推送到「回覆」並逐一訪問每個回覆。
是否有縮進每個孩子評論的好方法?
謝謝!
你能畫一個線框來理解你的觀點嗎? –
我正在描述reddit(和現在的臉書)上的縮進線程。 –