Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3955128
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:11:26+00:00 2026-05-20T02:11:26+00:00

I am creating a jsTree instance which shows a directory listing of a file

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T02:11:26+00:00Added an answer on May 20, 2026 at 2:11 am

    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"
       }
    ...
    ]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having difficulty creating a JTree that allows the nodes to be reorganized
Creating a zip file using Send To -> Compressed folder excludes .hg folder on
Creating a server-side socket will fail if I'm trying to use the same port
I am using jsTree for creating a documentation list index. I use JSON to
Creating a simple TCP server based on examples but still do not get how
Creating an iOS app in Flash Builder 4.5 which is a small Hello World
Creating a CMS, I have a settings table, in which I store many CMS
I'm trying to let the user create either a file or a folder. So
Creating a batch script in Windows XP. Here's a snippet of code I'm having
I have an instance of jstree. It is ajax with json. Here is how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.