D
D
Dmitry2016-10-05 11:41:03
JavaScript
Dmitry, 2016-10-05 11:41:03

How to build folder tree from json object?

b8724cf05e8d419d8f248a8878dc83a1.jpeg
There is an object in which there are Projects, there are 7 of them, I can easily find the desired project using lodash, let's say it's the 7th one as in the screenshot, then I know that there is an end folder with Id "e0685640 ..." it is also Meetings, I need finally build the project tree:
Project -> path (intermediate folders) -> destination folder
I only know the project and the id of the destination folder, you need to remove the intermediate folders, in this case it is "Bugs", but the nesting level can be anything, and can be that there is no nesting.
As a result, it should look like this Thick Client -> Bugs -> Meetings

// id оконечной папки
let folderId = "e0685640-8564-41c6-b53a-d67a8c6ab886";
// id проекта
let projectId = 'f04c9cb9-1907-4c30-acd4-deed91ba8f85';
// получаю индекс нужного мне проекта в массиве объектов
let projectIndex = _.findIndex(this.projects, {'Id': projectId});
// объект с нужным проектом
this.selectProject = this.projects[projectIndex];
//this.selectProject.Folders массив объектов с данными папок

I tried to recursively check, pull out the values, it didn’t work out, in fact, as I understand it, you need to find this id of the destination folder, if you find it, remember the path along which it lies, and then somehow pull out the name of the intermediate folders by reverse recursion.
I almost forgot, this is an Angular 2 class method written in TypeScript.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question