Ant design requires this kind of data structure to form various tree controls. This is really not as good as ztree and the like. People only need one array. After specifying the id and parentId, the tree will automatically appear. antd also I need to get children, I don’t think it’s any good
For example, the tree structure is like this
[ { id: '1', name: 'a', pid: '0', children: [ { id: '11', name: 'a-1', pid: '1', children: [ id: '111', name: 'a-1-1', pid: '11', children: null ] } ] }, { id: '2', name: 'b', pid: '0', children: null, } ]
So if we can quickly find the node with id: '111', can we only use recursive query? Is there a better way?
Perform the following operations on it:
Add child nodes: that is, in his children Add
to delete the node: that is, delete the node with id: '111'
Update node
Add a conversion layer and use id as the index for the reconstructed data