想請問
我mongodb有一樹狀結構資料
每筆資料都有
root_id -> string
task_id -> string
children -> array [child1, child2, ...]
由root_id 可以撈到一堆資料,代表由同一root_id 底下任務
每一個task_id 只知道他的children
第一層就是root_id = task_id
需要由他往下爬
現在問題是前端要顯示樹狀圖
需要資料結構如下
{
root_id: {
child1:{
child11:{
......
}
},
child2: {
....
}
}
}
遞迴去爬所有資料是知道怎麼做,
但是不知道怎麼組成array
請各位大神提點一下