要重新格式化层次结构节点对象的祖先路径

时间:2019-06-22 16:54:57

标签: javascript json mongodb

我使用祖先路径在mongodb中重新格式化了数据,以确保每个节点之间的关系,并打算在组织树视图中显示它。

[
{
    "isActive": true,
    "ancestorsPath": [],
    "studentGroup": [
        "t2-001",
        "t2-002",
        "t2-003"
    ],
    "_id": "33d9704f34901855c911e433",
    "email": "user5@test.com",
    "agentId": "t1-001"
},
{
    "isActive": true,
    "ancestorsPath": [],
    "studentGroup": [
        "t2-101",
        "t2-102",
        "t2-103"
    ],
    "_id": "5cdb0664c409e90e4fe21133",
    "email": "user5@test.com",
    "agentId": "t1-100",
},
{
    "isActive": true,
    "ancestorsPath": [
        "t1-001"
    ],
    "studentGroup": [
        "t3-001",
        "t3-002",
        "t3-003"
    ],
    "_id": "5cdb06dec409e90e4fe21134",
    "email": "user5@test.com",
    "agentId": "t2-001",
}
]

但是组织树中的数据使用的格式如下:

id: "T1-001",
    name: "user5@test.com",
    title: "general manager",
    children: [
      {
        id: "t2-001",
        name: "Bo Miao",
        title: "department manager",
        number: "MYR 2,000"
      },
      {
        id: "t2-002",
        name: "Su Miao",
        title: "department manager",
        children: [
          { id: "t3-001", name: "Tie Hua", title: "senior engineer" },
          {
            id: "t3-002",
            name: "Hei Hei",
            title: "senior engineer",
            children: [
              { id: "6", name: "Pang Pang", title: "engineer" },
              { id: "7", name: "Xiang Xiang", title: "UE engineer" }
            ]
          }
        ]
      },
      { id: "t2-003", name: "Hong Miao", title: "department manager" }

我应该如何格式化我的数据?谁能给我一些指导,以便我进一步学习?

0 个答案:

没有答案