0

我正在关注这个关于使用祖先的 railscast 剧集: http ://railscasts.com/episodes/262-trees-with-ancestry

我不了解地图方法。有人可以解释“sub_messages”是如何工作的吗?

def nested_messages(messages)
  messages.map do |message, **sub_messages**|
    render(message) + content_tag(:div, nested_messages(sub_messages), :class => "nested_messages")
  end.join.html_safe
end
4

1 回答 1

1

When you call map on a hash, it iterates through the hash and (in your example), assigns the key to message and the value to sub_messages.

于 2013-03-05T20:43:51.473 回答