I'm trying to make a table like this:
| --------
| - <Tr>
| + <Tr>
| - <Tr>
| - <Tr>
| - <Tr>
| <Tr>
| <Tr>
| <Tr>
| + <Tr>
| + <Tr>
Table elements can contain thousands of child dropdown elements.
I am writing code in React and so far I have no idea and have not figured out how it can be done in a more optimized way.
Right now I am trying to work with a data structure like this
[
{
id: 1,
childrens: [
{ id: 10, childrens: [] },
{ id: 11, childrens: [{ id: 12, childrens: [] }] },
],
},
{ id: 2, childrens: [] },
];
Current implementation idea:
When I click on the dropdown element, I do the following:
- Get id
- I am looking for an element in the array by id
- I get the contents of
childrens, if the array contains data, then I add them after the parent<tr>element
To hide the dropdown <tr> I do the following:
- Get id
- I am looking for an element in the array by id
- Get the length of the array
childrens - I delete after the parent
<trelement, the number of child<tris equal to the length of the array
But I don't understand how I can work with nested child elements. I need to somehow understand who is the parent of whom in order not to bypass the entire array again.
In what direction should I explore this issue?