1

好的,这可能是一个真正简单的请求。

但是,我有 4 个 JSON 文件,好吧,我在 GET 到一个

//一些IP地址/一些目录/一些子目录/文件夹名称

所以我回来让我们说,网络、站点、资源、组件

NETWORKS 下面的每一个都是 CHILD...

好的,接下来:我需要组合这些 JSON 文件来填充 JSTree(来自 jstree.com)

我有一个像这样的基本 JSON 文件,它工作得很好:

(注意:下面的 ID 是无关紧要的,并且在下面的真实示例中不匹配。)

这里的目的是将我通过 RESTful 环境获得的所有四个 JSON 对象加入到从数据库获取数据的 JAVA API。

[
{
    "data": "Network 1",
    "metadata": {"id" : "n1"},
    "children": [ {  

            "data": "Site 1",
            "metadata": {"id" : "s1"},
            "children": [ {  

                "data": "Resource 1",
                "metadata": {"id" : "r1"},
                "children": [ 

                        {
                            "data": "Component 1",
                            "metadata": {"id" : "c1"}
                        },
                        {
                            "data": "Component 2",
                            "metadata": {"id" : "c2"}
                        },
                        {
                            "data": "Component 3",
                            "metadata": {"id" : "c3"}
                        } ] } ] },

                    "Site 2",

                    "Site 3",

                    "Site 4"]
}
]

这是我的困境:

我需要组合以下 JSON 文件:SITES、RESOURCES 和 COMPONENTS

简单吧?没那么多。

以下是每个较低级别 JSON 对象的示例:

网络:

[
  {
    "id": "23ef0d23-0d8d-4466-98da-81ef30791773",
    "notes": "This is a network for network 1",
    "name": "n1"
  },
  {
    "id": "b4b46748-511a-49bf-9d22-8da014c76cc2",
    "notes": "This is a network for network 2",
    "name": "n2"
  },
  {
    "id": "678b4a01-a6a6-449f-966d-c50c74964729",
    "notes": "This is a network for network 3",
    "name": "n3"
  },
  {
    "id": "8e2822b1-49a8-498e-979b-2849cfa82148",
    "notes": "This is a network for network 4",
    "name": "n4"
  }
]

网站:

[
  {
    "id": "05683e7b-e471-4417-bead-317cfcbfaf30",
    "name": "s1",
    "networkId": "23ef0d23-0d8d-4466-98da-81ef30791773",
    "notes": "This is site 1"
  },
  {
    "id": "de8d654c-f9c4-4a4e-8742-32794b218b54",
    "name": "s2",
    "networkId": "23ef0d23-0d8d-4466-98da-81ef30791773",
    "notes": "This is site 2"
  },
  {
    "id": "16b2b1cf-2991-4717-ae65-2158700fa95d",
    "name": "s3",
    "networkId": "8e2822b1-49a8-498e-979b-2849cfa82148",
    "notes": "This is site 3"
  }
]

资源:

[
  {
    "id": "26db6a18-5099-4117-9adb-b8c808a3c478",
    "networkId": "23ef0d23-0d8d-4466-98da-81ef30791773",
    "siteId": "05683e7b-e471-4417-bead-317cfcbfaf30",
    "name": "r1",
    "notes": "This is Resource 1"
  },
  {
    "id": "26ad2b53-f4b2-41c1-a618-d9e710452b7f",
    "networkId": "23ef0d23-0d8d-4466-98da-81ef30791773",
    "siteId": "05683e7b-e471-4417-bead-317cfcbfaf30",
    "name": "r2",
    "notes": "This is Resource 2"
  }
]

最后,组件:

[
  {
    "id": "6e8d13ad-9eb6-4213-bf84-a6e91d2e1460",
    "resourceId": "26ad2b53-f4b2-41c1-a618-d9e710452b7f",
    "siteId": "05683e7b-e471-4417-bead-317cfcbfaf30",
    "networkId": "23ef0d23-0d8d-4466-98da-81ef30791773",
    "name": "Component 1",
    "notes": "This is my very first component - Yay!"
  },
  {
    "id": "8f18cca3-378e-4f9b-8a39-eb2285fa61fd",
    "resourceId": "26ad2b53-f4b2-41c1-a618-d9e710452b7f",
    "siteId": "05683e7b-e471-4417-bead-317cfcbfaf30",
    "networkId": "23ef0d23-0d8d-4466-98da-81ef30791773",
    "name": "Component 2",
    "notes": "This is my Second component - Yay!"
  },
  {
    "id": "539370a6-577f-477d-a6ea-d45efd7e65aa",
    "resourceId": "26ad2b53-f4b2-41c1-a618-d9e710452b7f",
    "siteId": "05683e7b-e471-4417-bead-317cfcbfaf30",
    "networkId": "23ef0d23-0d8d-4466-98da-81ef30791773",
    "name": "Component 3",
    "notes": "This is my Third component - Yay!"
  }
]

最终,当结合起来时,它看起来就像第一个适用于 JSTree 的 JSON 示例。

谢谢大家的帮助。

问候

4

0 回答 0