File Explorer using Dojo Tree from an Array

875 Views Asked by At

I have an array of file names/paths. Lets say it contains:

  • File1.txt
  • Folder1/File2.txt
  • Folder1/File3.txt
  • Folder2/File4.txt
  • Folder3/Folder4/File5.txt
  • Folder3/File6.txt
  • NewFile.txt

Now I want to create a Dojo Tree which basically displays this information in a tree structure with root as "Files" and below it appears a tree like this

  • Files (ROOT)
    • File1.txt
    • Folder1
      • File2.txt
      • File3.txt
    • Folder2
      • File4.txt
    • Folder3
      • Folder4
        • File5.txt
      • File6.txt
    • NewFile.txt

I was able to create a JSON form single level tree structure. As I am hard pressed for time I need a algorithm/code snippet which can create my desired JSON file. Any ideas!?

1

There are 1 best solutions below

0
On BEST ANSWER

Take a look at giveSortedArray() function (yeah I suck at function naming):

http://jsfiddle.net/QDAjz/

I used dojo.store.Memory for easier fetching of existing folders but I'm sure there are some other (possible better) solutions.