-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Description
Hi,
I am working in React with TypeScript. I am using the below JSON format to build the tree structure to display the content as folder. I stored the below JSON data in state object as treeViewData.
{
"path": "Parent Site",
"name": "Parent Site",
"type": "directory",
"isRoot": true,
"children": [
{
"path": "Parent Site/Sub Site 1",
"name": "Sub Site 1",
"type": "directory",
"children": [
{
"path": "Parent Site/Sub Site 1/Documents",
"name": "Documents",
"type": "directory",
"children": []
},
{
"path": "Parent Site/Sub Site 1/My Documents",
"name": "Documents",
"type": "directory",
"children": [
{
"path": "Parent Site/Sub Site 1/My Documents/Folder1",
"name": "Folder1",
"type": "directory”,
"children": []
},
{
"path": "Parent Site/Sub Site 1/My Documents/Folder2",
"name": "Folder2",
"type": "directory”,
"children": []
}
]
},
{
"path": "Parent Site/Sub Site 1/My New Documents",
"name": "Documents",
"type": "directory",
"children": []
}
]
},
{
"path": "Parent Site/Sub Site 2",
"name": "Sub Site 2",
"type": "directory",
"children": [
{
"path": "Parent Site/Sub Site 2/Documents",
"name": "Documents",
"type": "directory",
"children": [
{
"path": "Parent Site/Sub Site 2/Documents/Folder1",
"name": "Folder1",
"type": "directory”,
"children": []
},
{
"path": "Parent Site/Sub Site 2/Documents/Folder2",
"name": "Folder2",
"type": "directory”,
"children": []
},
{
"path": "Parent Site/Sub Site 2/Documents/Folder3",
"name": "Folder3",
"type": "directory",
"children": []
}
]
}
]
}
]
}
From the above JSON data, I want to insert new set of properties in the Children object. Let us consider the below child which is resided in the Parent Site/Sub Site 2.
"path": "Parent Site/Sub Site 2/Documents/Folder1",
In this current node, Children array is empty. I want to insert new set of four properties to be added like below.
"path": "Parent Site/Sub Site 2/Documents/Folder1/Inside New Folder",
"name": "Inside New Folder",
"type": "directory”,
"children":[]
How to do this in React? How to perform the setState operation of this scenario? Please help me.
Thanks
Philip