I have written a function which scans all the files/directory in a given directory and returns a json object. I need to display this json object on the UI using jstree. I have written the function in go using recursion to scan all the files and directories rooted at that particular folder.
This is the type I am using to construct the whole structure
type Directory struct {
Name string "data"
SubDirs []Directory "children"
}
Now jstree accepts data structs of the following format.
json_data: {
data: [
"f1",
"f2",
{
data: "f3",
children: ["f4", "f5"]
}
]
}
and not of the format :-
json_data: {
data: [
{
"data": "f1",
"children": []
}
{
"data": "f2",
"children": []
}
{
data: "f3",
children: ["f4", "f5"]
}
]
}
(when I pass the above data structure format, it doesn't work probably since the "children" thing is null)
Thus the data structure Directory I have maintained doesn't suffice to construct the directory structure.
How do I solve this problem of constructing the Directory tree homogeneously?