-1
樹結構我想從以下數據生成樹型結構:紅寶石產生從平面陣列
[
{"first_name" => "Test", "id" => "1", "parent_id" => ""},
{"first_name" => "Test1", "id" => "2", "parent_id" => "1"},
{"first_name" => "Test2", "id" => "3", "parent_id" => "1"},
{"first_name" => "Test3", "id" => "4", "parent_id" => "2"}
]
我想創建Ruby腳本來構建以下結構:
[
{
"first_name" => "Test",
"id" => "1",
"children" => [
{
"first_name" => "Test1",
"id" => "2",
"children" => [
{
"first_name" => "Test3",
"id" => "4"
}
]
},
{
"first_name" => "Test2",
"id" => "3"
}
}
]
你有在這種情況下的一些提示?
這是功課嗎? – Max
與http://stackoverflow.com/q/18829289/3910390重複 – Penguin