1 | export const getTreePathFromId = (flatData, id) => { |
||
2 | const res = []; |
||
3 | const node = flatData.find(n => n.get('_id') === id); |
||
4 | const finder = n => n.get('_id') === lastParentId; |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
5 | let lastParentId = node.get('_id'); |
||
6 | |||
7 | while (lastParentId !== undefined) { |
||
8 | const parent = flatData.find(finder); |
||
9 | |||
10 | if (parent) { |
||
11 | res.push(parent.get('_id')); |
||
12 | lastParentId = parent.get('_parentId'); |
||
13 | } |
||
14 | |||
15 | else { |
||
16 | lastParentId = undefined; |
||
17 | } |
||
18 | } |
||
19 | |||
20 | return res.reverse(); |
||
21 | }; |
||
22 |