JStree:从smbclient目录结构创建jstree

时间:2015-01-19 05:29:43

标签: ruby-on-rails jstree directory-listing

我正在为smbclient使用sambal gem。 我想从smbclient的递归目录列表中创建jstree。

require "sambal"
client = Sambal::Client.new(domain:domain-name, host: host, share: 'all' ,user: 'abc', password: 'pswd')
client.cd("abc")
client.ask("recurse")
all_files_hash = client.ask("ls")

我修改了smbclient的parse_files方法,在文件列表哈希中有路径。 我希望在JStree中显示的目录列表的示例哈希:

    all_files_hash = {"."=>{:type=>:directory}, ".."=>{:type=>:directory}, 
    "log"=>{:type=>:directory, :path=>"\\abc"},
     "softwares"=>{:type=>:directory, :path=>"\\abc"}, 
    "test.txt"=>{:type=>:file, :path=>""},
 "test_data"=>{:type=>:directory, :path=>"\\abc"},
 ".keep"=>{:type=>:file, :path=>"\\abc\\log"},
 "alert.log"=>{:type=>:file, :path=>"\\abc\\log"}, 
"development.log"=>{:type=>:file, :path=>"\\abc\\log"},
 "test.log"=>{:type=>:file, :path=>"\\abc\\test_data"},
 "robomongo-0.8.4-x86_64.deb"=>{:type=>:file, :path=>"\\abc\\softwares"}, 
"sublime-text_build-3065_amd64.deb"=>{:type=>:file, :path=>"\\abc\\softwares"},
 "ubuntu"=>{:type=>:directory, :path=>"\\abc\\softwares"},
 "ubuntu.css"=>{:type=>:file, :path=>"\\abc\\softwares\\ubuntu"}} 

如何从all_files_hash中的recursive文件列表中创建jstree?

预期产出:

 jstree_hash = [{"text" => "abc","path" => "\\abc","children" => [{"text" => "log","path"=>"\\abc\\log","children" => [{"text" => "development.log","path"=>"\\abc\\log\\developemnt.log"},{"text" => "alert.log","path"=>"\\abc\\log\\alert.log"}]}]}}]

我按照以下链接但没有运气: nested hashiterate over deep hash

提前致谢..

0 个答案:

没有答案