I have JSON data and I want to read all the data and make a dropdown list. Here is the sample code I have written. In this code only 2nd level it is showing. I want all levels.
{
menu_data.map((menu)=>(
menu.children ?
<div class="menu-item sub-nav">{menu.name}
<div class="menu-container">{menu.children.map((child)=>(<div class="menu-item"><a href={child.url}>{child.name}</a></div>))}</div>
</div>
:
<div class="menu-item">{menu.name}</div>
))
}
The JSON data looks like
[{
"name": "ABC",
"url": "/abc.html"
},
{
"name": "XYZ",
"children": [{
"name": "PQR",
"url": " /pqr.jsp"
},
{
"name": "MOB",
"url": "/hello"
},
{
"name": "TOC",
"children": [
{
"name": "LOL",
"url": "/hello"
},
{
"name": "RST",
"url": "/hello"
},
{
"name": "NULL",
"url": "/hello"
}
]
},
]
}
]
},
{
"name": "def",
"url": "/def.html"
}
]
please refer to this screenshot. in this way, I want to show. enter image description here
Anyone has any idea.
How to solve this problem.