的陣列我有一個數組排序的文件列表,如:從文件列表,動態創建哈希爲dynatree
arr = ["./a.txt", "./b.txt", "./bar/z.php", "./foo/hello/y.php", "./foo/x.php"]
如何創建一個dynatree對象出來呢? 爲它dynatree對象,應該是這樣的:
[{"name"=>".", "title" => ".", "isDir" => true, "children" =>
[{"name"=>"a.txt", "title" => "a.txt"},
{"name"=>"b.txt", "title" => "b.txt"},
{"name" => "bar", "title"=>"bar", "isDir"=>true, "children" =>
[{"name" => "z.php", "title" => "z.php"},
{"name" => "foo", "title" => "foo", "isDir" => true, "children" =>
[{"name" => "x.php", "title" => "x.php"},
{ "name" => "hello", "title" => "hello", "children" =>
[{"name" => "y.php", "title"=>"y.php"}
]
}
]
}
]
}
]
}]
PS:這個問題似乎是一個懶惰的職位,但我已經花了20個多小時,現在解決這個。所以任何幫助將不勝感激。謝謝。
您的需求總是...... *難* * :-) – 2014-09-05 09:08:37