我有一个JSON数组。我尝试转换嵌套分层树。但它没有工作。我需要一个使用这个JSON的分层树。Json使用分层树使用javascript
这里是我的数据:
[{
"_id" : "59b65ee33af7a11a3e3486c2",
"C_TITLE" : "Sweet and Snacks",
"C_PARENT" : "0",
"C_ICON" : "",
"C_IMAGE" : "59b65ee33af7a11a3e3486c2_sweets.jpg",
"C_STATUS" : "Active"
}
{
"_id" : "59b663d709da571dc3d79f49",
"C_TITLE" : "Groceries",
"C_PARENT" : "0",
"C_ICON" : "",
"C_IMAGE" : "59b663d709da571dc3d79f49_grocery.jpg",
"C_STATUS" : "Active"
},
{
"_id" : "59b6648209da571dc3d79f4a",
"C_TITLE" : "Dals & Pulses",
"C_PARENT" : "59b663d709da571dc3d79f49",
"C_ICON" : "",
"C_IMAGE" : "59b6648209da571dc3d79f4a_dals.jpg",
"C_STATUS" : "Active"
},
{
"_id" : "59b6657509da571dc3d79f4c",
"C_TITLE" : "Rice & Rice products",
"C_PARENT" : "59b663d709da571dc3d79f49",
"C_ICON" : "",
"C_IMAGE" : "59b6657509da571dc3d79f4c_rice.jpg",
"C_STATUS" : "Active"
}]
我需要这样的输出
[
{
" _id" : "59b65ee33af7a11a3e3486c2",
"C_TITLE" : "Sweet and Snacks",
"C_PARENT" : "0",
"C_ICON" : "",
"C_IMAGE" : "59b65ee33af7a11a3e3486c2_sweets.jpg",
"C_STATUS" : "Active",
children:[]
}
]
基于Check C_PARENT和_id。
可以添加您的预期输出 – prasanth
[ \t { \t \t “_id”: “59b65ee33af7a11a3e3486c2”, \t \t “C_TITLE”: “甜零食”, \t \t “C_PARENT”:“0”, \t \t“C_ICON”:“”, \t \t “C_IMAGE”: “59b65ee33af7a11a3e3486c2_sweets.jpg”, \t \t “C_STATUS”: “活动”, \t \t孩子:{ \t \t “_id”: “ghhgfhfhhhg”, \t \t \t “C_TITLE”:“甜零食 “ \t \t \t ”C_PARENT“: ”59b65ee33af7a11a3e3486c2“, \t \t \t ”C_ICON“: ”“, \t \t \t ”C_IMAGE“:” 59b65ee33af7a1 1a3e3486c2_sweets.jpg”, \t \t \t “C_STATUS”: “活跃”, \t \t} \t} ] – sarankani
感谢乌尔reply.I需要上面的输出。 – sarankani