我从数据库取到的数据如下:
planList := [{1 'plan1'}] // [{plan_id title}]
promotionList := [{1 2 'promotion1'}, {1 6 'promotion2'}] // [{plan_id promotion_id title}]
creativeList := [{2 3 "creative1"}, {2 4 "creative2"}] // [{promotion_id creative_id title}]
我想把planList promotionList creativeList整理成一个如下格式json返回给前端:
{
"menuData": [
{
"title": "plan1",
"id": "1",
"subs": [
{
"title": "promotion1",
"id": "2",
"subs": [
{"title": "creative1", "id": "3"},
{"title": "creative2", "id": "4"}
]
},
{
"title": "promotion2"
"id": "6",
"subs": []
}
]
},
{
"title": "plan2"
"id": 9,
"subs": []
}
]
}
就是一个plan的subs属性中有0到多个promotion数据,一个promotion的subs属性中有0到多个creative数据。promotion通过paln_id找到自己属于哪个plan,creative通过promotion_id找到自己属于哪个promotion。
请问数据要怎么整理
定义者这样的结构体。
然后 for range 下面三个数组进行 渲染数据
planList
promotionList
creativeList