渲染的 jsTree 不反映“关闭” JSON数据节点的状态

发布于 2024-10-15 22:58:11 字数 3113 浏览 2 评论 0原文

我正在创建一个 jsTree 实例,它显示文件服务器的目录列表。我很难将 jsTree 的“子文件夹”或“子目录”节点显示为可打开。

虽然文件夹节点的 JSON stateclose,但 jsTree 的显示不会显示该节点的打开/关闭三角形。

以下是我的 #fileTree 的初始配置:

$("#fileTree")
    .jstree({
        "core" : { 
            "initially_open" : [ "root" ] ,
            "html_titles" : false
        },

        "json_data" : {                
            "progressive_render" : true,                
            "data" : [
                {
                    "data" : { title : "/home/" + username },
                    "attr" : {
                        "id" : "/home/" + username,
                        "rel" : "root",
                        "href" : "file://home/" + username
                    },          
                    "icon" : "/js/_demo/home.png",
                    "state" : "closed"
                }   
            ],
            "ajax" : {
                "url" : "/services/listDirectoryContents.pl",
                "data" : function (n) { 
                    return { id : n.attr ? n.attr("id") : "/home/" + username }; 
                }
            }
        },

        "themes": {
            "theme": "default",
            "dots": true,
            "icons": true,
            "url": "/js/themes/default/style.css"
        },

        "plugins" : [ "core", "themes", "json_data" ]
    });

ajax 小节调用的 /services/listDirectoryContents.pl 脚本是一个近乎 RESTful 的脚本它将路径作为查询参数(节点的 id 中的内容)。

该服务以 JSON 格式输出一组目录和文件(最大深度为 1),以及供 jsTree 使用的显示属性。

以下是该服务的示例输出,使用 /home/areynolds 作为根节点:

$ ./listDirectoryContents.pl /home/areynolds
Status: 200 OK
Content-Type: text/html; charset=ISO-8859-1

[
   {
      "data" : {
         "icon" : "/js/_demo/folder.png",
         "title" : "projects",
         "attr" : {
            "rel" : "folder",
            "href" : "file:///home/areynolds/projects",
            "id" : "/home/areynolds/projects"
         },
         "state" : "closed"
      }
   },
   {
      "data" : {
         "icon" : "/js/_demo/folder.png",
         "title" : "proj",
         "attr" : {
            "rel" : "folder",
            "href" : "file:///home/areynolds/proj",
            "id" : "/home/areynolds/proj"
         },
         "state" : "closed"
      }
   },

   ...

   {
      "data" : {
         "icon" : "/js/_demo/file.png",
         "title" : "test.bed",
         "attr" : {
            "rel" : "file",
            "href" : "file:///home/areynolds/test.bed"
         }
      }
   }
]

在我的网页上,根节点(例如 /home/areynolds)最初是关闭的— 有趣的是,尽管 core 插件的 initially_open 指令:

关闭的根节点

当我打开根节点时,我会看到根节点下的文件夹和文件列表:

打开的根节点

显示文件夹和文件的正确图标标题数据。

但是,每个文件夹旁边没有打开/关闭显示三角形。 (理论上,打开时,这将触发对打开的子目录的文件夹和文件列表的 Ajax 调用。)

我的 JSON 输出或初始 $("#fileTree"). 如何配置错误? jstree() 设置,以便防止打开/关闭三角形出现?

感谢您的建议!

I am creating a jsTree instance which shows a directory listing of a file server. I am having difficulties getting "sub-folder" or "sub-directory" nodes of a jsTree to display as open-able.

While the folder-node's JSON state is closed, the display of the jsTree does not show the open/close triangle for that node.

Here is the initial configuration of my #fileTree:

$("#fileTree")
    .jstree({
        "core" : { 
            "initially_open" : [ "root" ] ,
            "html_titles" : false
        },

        "json_data" : {                
            "progressive_render" : true,                
            "data" : [
                {
                    "data" : { title : "/home/" + username },
                    "attr" : {
                        "id" : "/home/" + username,
                        "rel" : "root",
                        "href" : "file://home/" + username
                    },          
                    "icon" : "/js/_demo/home.png",
                    "state" : "closed"
                }   
            ],
            "ajax" : {
                "url" : "/services/listDirectoryContents.pl",
                "data" : function (n) { 
                    return { id : n.attr ? n.attr("id") : "/home/" + username }; 
                }
            }
        },

        "themes": {
            "theme": "default",
            "dots": true,
            "icons": true,
            "url": "/js/themes/default/style.css"
        },

        "plugins" : [ "core", "themes", "json_data" ]
    });

The /services/listDirectoryContents.pl script called from the ajax subsection is a near-RESTful script that takes a path as a query argument (whatever is in the id of the node).

The service outputs an array of directories and files in JSON format (at a maxdepth of 1), along with display attributes for use by jsTree.

Here is sample output from this service, using /home/areynolds as the root node:

$ ./listDirectoryContents.pl /home/areynolds
Status: 200 OK
Content-Type: text/html; charset=ISO-8859-1

[
   {
      "data" : {
         "icon" : "/js/_demo/folder.png",
         "title" : "projects",
         "attr" : {
            "rel" : "folder",
            "href" : "file:///home/areynolds/projects",
            "id" : "/home/areynolds/projects"
         },
         "state" : "closed"
      }
   },
   {
      "data" : {
         "icon" : "/js/_demo/folder.png",
         "title" : "proj",
         "attr" : {
            "rel" : "folder",
            "href" : "file:///home/areynolds/proj",
            "id" : "/home/areynolds/proj"
         },
         "state" : "closed"
      }
   },

   ...

   {
      "data" : {
         "icon" : "/js/_demo/file.png",
         "title" : "test.bed",
         "attr" : {
            "rel" : "file",
            "href" : "file:///home/areynolds/test.bed"
         }
      }
   }
]

On my web page, the root node (e.g. /home/areynolds) is initially closed — interestingly, despite the core plug-in's initially_open directive:

Closed root node

When I open the root node, I see a list of folders and files underneath the root node:

Opened root node

The correct icon and title data are shown for folders and files.

However, there are no open/close disclosure triangles next to each folder. (When opened, in theory, this would trigger an Ajax call for the list of folders and files of the opened sub-directory.)

How have I misconfigured in my JSON output or my initial $("#fileTree").jstree() setup, such that the open/close triangles are prevented from showing up?

Thanks for your advice!

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

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

发布评论

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

评论(1

红玫瑰 2024-10-22 22:58:11

attr 属性的位置似乎决定了 jsTree 的成败。以下是正常工作的文件夹节点的示例:

[
...
   {
      "data" : {
         "icon" : "/js/_demo/folder.png",
         "title" : "workspace",
         "attr" : {
            "href" : "file:///home/areynolds/workspace"
         }
      },
      "attr" : {
         "rel" : "folder",
         "id" : "/home/areynolds/workspace"
      },
      "state" : "closed"
   }
...
]

The location of the attr attributes seems to make or break jsTree. Here is an example of a folder node that works properly:

[
...
   {
      "data" : {
         "icon" : "/js/_demo/folder.png",
         "title" : "workspace",
         "attr" : {
            "href" : "file:///home/areynolds/workspace"
         }
      },
      "attr" : {
         "rel" : "folder",
         "id" : "/home/areynolds/workspace"
      },
      "state" : "closed"
   }
...
]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文