Dynatree 有加载 json 格式指南吗?

发布于 2024-12-28 02:04:51 字数 1285 浏览 5 评论 0原文

我正在尝试通过 ajax 使用 json 对象加载 dynatree。我无法控制对象内的 json 名称和值。它们将采用以下格式。我无法加载树。 json 是否需要采用特定格式才能正确加载?

这是 JSON

{
   "root":true,
   "topNode": {
      "containerId":"1",
      "children":[
         {
            "containerId":"2",
            "children":[

            ],
            "root":false
         },
         {
            "containerId":"3",
            "children":[
               {
                  "containerId":"4",
                  "children":[

                  ],
                  "root":false
               }
            ],
            "root":false
         },
         {
            "containerId":"5",
            "children":[
               {
                  "containerId":"6",
                  "children":[

                  ],
                  "root":false
               },
               {
                  "containerId":"7",
                  "children":[

                  ],
                  "root":false
               }
            ],
            "root":false
         } 
      ],
      "root":true
   }
}

这是 Javascript:

      $(function(){
        $("#treeView").dynatree({
              initAjax: {
                  url: "/myURL",
                  },
        });
      });

I am trying to load dynatree using a json object via ajax. I dont have control over the json names and values inside the object. They will be in the format below. I have not been able to get the tree to load. Is there a specific format the json needs to be in, in order to load properly?

Here is the JSON

{
   "root":true,
   "topNode": {
      "containerId":"1",
      "children":[
         {
            "containerId":"2",
            "children":[

            ],
            "root":false
         },
         {
            "containerId":"3",
            "children":[
               {
                  "containerId":"4",
                  "children":[

                  ],
                  "root":false
               }
            ],
            "root":false
         },
         {
            "containerId":"5",
            "children":[
               {
                  "containerId":"6",
                  "children":[

                  ],
                  "root":false
               },
               {
                  "containerId":"7",
                  "children":[

                  ],
                  "root":false
               }
            ],
            "root":false
         } 
      ],
      "root":true
   }
}

Here is the Javascript:

      $(function(){
        $("#treeView").dynatree({
              initAjax: {
                  url: "/myURL",
                  },
        });
      });

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏の忆 2025-01-04 02:04:51

您可以使用标准 jQuery $.json()$.ajax 读取数据,然后处理接收到的 JSON,例如使用 dataFilter > 钩子。

作为替代方案,您可以实现 dynatree 的(尚未记录)postProcess(data, dataType) 回调。

You could read your data with standard jQuery $.json() or $.ajax, and then process the received JSON, for example using the dataFilter hook.

As an alternative you could implement dynatree's (yet undocumented) postProcess(data, dataType) callback.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文