how to create tree structure recursive json & query for it ,where id =5 in nodejs
问题 Table for my folder structure id | name | parent_id ----+--------------+----------- 1 | parent | 2 | child | 1 3 | grandchild A | 2 4 | grandchild B | 2 5 | grandchild c | 3 select id,parent_id, name from table. I want to create a json for this result set which should be in tree structure. how to make a json for this, please help. 回答1: Something like this? { "1": { "name": "parent", "parent_id": 0 }, "2": { "name": "child", "parent_id": 1 }, "3": { "name": "grandchild a", "parent_id": 2 } }