❔ Creating a hierarchy algorithm

I have an image model, which consists of public Guid Id { get; set; } public string Name { get; set; } public List<string> VirtualDir { get; set; } virtual dir is the directory the image is stored in, split into a list of strings so one example: ["folder1","folder1child", "image"] Now, if i want to create a Hierarchy of the whole directory showing all images in the different folders represented as JSON, something like the below. { text: 'Folder 1', children: [{ name: 'image 1' }, { name: 'image 2' }, { name: 'image 2' }], }, { text: 'Folder 2', children: [ { name: 'folder 2 child folder', children: [{ name: 'image 1' }] }, { name: 'image 2' }, { name: 'image 2' }, ], }, How can i successfully archive this?
3 Replies
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Spixy
Spixy2y ago
You need to put it into tree data structure, which you then serialize into JSON.
class Node {
String Name { get; set; } // Name or Text or both
List<Node> Children { get; set; }
}
class Node {
String Name { get; set; } // Name or Text or both
List<Node> Children { get; set; }
}
like this
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server