I have a array as follows:
[{
"data": {
"name": "Cloud",
"size": "20mb",
"type": "Folder",
"isDisplayStatus": 1
},
"children": [
{
"data": {
"id":1,
"name": "backup-1.zip",
"size": "10mb",
"type": "Zip",
"isDisplayStatus": 1
}
},
{
"data": {
"id":2,
"name": "backup-2.zip",
"size": "10mb",
"type": "Zip",
"isDisplayStatus": 1
}
}
]
},
{
"data": {
"name": "Desktop",
"size": "150kb",
"type": "Folder",
"isDisplayStatus": 0
},
"children": [
{
"data": {
"id":3,
"name": "note-meeting.txt",
"size": "50kb",
"type": "Text",
"isDisplayStatus": 0
}
},
{
"data": {
"id":4,
"name": "note-todo.txt",
"size": "100kb",
"type": "Text",
"isDisplayStatus": 1
}
}
]
}]
I have a method in which I will receive two arguments. One is boolean value and one is id.
-
If boolean value is false, then I need to find the element in the array for the id which is coming as argument of method and set “isDisplayStatus” field to 0.
-
If boolean value is true, then I need to find the element in the array for the id which is coming as argument of method and set “isDisplayStatus” field to 1.
-
If for any children “isDisplayStatus” is 0, then “isDisplayStatus” in parent should be set as 0. If all chilren “isDisplayStatus” is 0, then for parent “isDisplayStatus” should be 0. If all children “isDisplayStatus” is 1, then for parent “isDisplayStatus” should be 1.
How can I do this?