我有一个带有字段的C_PARENT
对象列表。此父字段引用列表中的另一个对象。我想根据这个字段从这个列表中创建一个树层次结构。
这是我的数据。
[{
"C_ID" : 1.0,
"C_TITLE" : "Sparklers",
"C_PARENT" : 0.0,
"C_STATUS" : "Active"
},
{
"C_ID" : 2.0,
"C_TITLE" : "Twinklers",
"C_PARENT" : 0,
"C_STATUS" : "Active"
},
{
"C_ID" : 3.0,
"C_TITLE" : "Candles",
"C_PARENT" : 0.0,
"C_STATUS" : "Active"
},
{
"C_ID" : 4.0,
"C_TITLE" : "Chakkars",
"C_PARENT" : 0.0,
"C_STATUS" : "Active"
},
{
"C_ID" : 5.0,
"C_TITLE" : "Colour Chakkars",
"C_PARENT" : 4.0,
"C_STATUS" : "Active"
},
{
"C_ID" : 6.0,
"C_TITLE" : "Fancy Chakkars",
"C_PARENT" : 4.0,
"C_STATUS" : "Active"
},
{
"C_ID" : 7.0,
"C_TITLE" : "Fountains",
"C_PARENT" : 0.0,
"C_STATUS" : "Active"
},
{
"C_ID" : 8.0,
"C_TITLE" : "Whistling Fountains",
"C_PARENT" : 7.0,
"C_STATUS" : "Active"
},
{
"C_ID" : 9.0,
"C_TITLE" : "Fancy Fountains",
"C_PARENT" : 7.0,
"C_STATUS" : "Active"
},
{
"C_ID" : 10.0,
"C_TITLE" : "Fancy Colour Fountains",
"C_PARENT" : 7.0,
"C_STATUS" : "Active"
},
{
"C_ID" : 11.0,
"C_TITLE" : "Rockets",
"C_PARENT" : 0.0,
"C_STATUS" : "Active"
}]
我需要转换成树结构。
[
{
'C_ID': 1,
'C_TITLE': 'Sparklers',
'C_PARENT': 0,
'C_STATUS':'Active'
},
{
"C_ID" : 2.0,
"C_TITLE" : "Twinklers",
"C_PARENT" : 0,
"C_STATUS" : "Active"
},
{
"C_ID" : 3.0,
"C_TITLE" : "Candles",
"C_PARENT" : 0.0,
"C_STATUS" : "Active"
}
{
'"C_ID" : 4.0,
"C_TITLE" : "Chakkars",
"C_PARENT" : 0.0,
"C_STATUS" : "Active"
children: [
{
"C_ID" : 5.0,
"C_TITLE" : "Colour Chakkars",
"C_PARENT" : 4.0,
"C_STATUS" : "Active"
},
{
"C_ID" : 6.0,
"C_TITLE" : "Fancy Chakkars",
"C_PARENT" : 4.0,
"C_STATUS" : "Active"
}
]
]
我不知道。
请给我建议,
谢谢