Skip to content
Code to generate a JSON file hierarchy for jQuery UI's jsTree.
Python Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
CHANGELOG.md
LICENSE
NOTICE
README.md
jstree.py
jstree_test.py
release.sh
setup.py

README.md

py-jstree

An introduction will be proposed later.

Installation

If you have Python installed and wish to get the package directly from the Python Package Index, just run pip install jstree from the command-line. If you already have a prior version installed, just run pip install jstree -U instead.

Contribute

Please help contribute to this project by going to the GitHub Project Repository and doing one of a few things:

  • send me pull requests through the github interface
  • point me directly to your git repo so I can pull changes
  • send bug reports and feature requests by filing them under the Issues tab at the top

Examples

>>> import jstree
>>> node = jstree.Node('a', None)
>>> print node
Node({'text': 'a', 'children': MutableDictionaryObject({})})
>>> print node.jsonData()
{'text': 'a'}

>>> import jstree
>>> node = jstree.Node('a', 1)
>>> print node
Node({'text': 'a', 'children': MutableDictionaryObject({}), 'li_attr': DictionyObject({'id': 1}), 'id': 1})
>>> print node.jsonData()
{'text': 'a', 'id': 1, 'li_attr': {'id': 1}}

>>> import jstree
>>> node = jstree.Node('a', 5, icon="folder", state = {'opened': True})
>>> print node
Node({'text': 'a', 'id': 5, 'state': DictionaryObject({'opened': True}), 'children': MutableDictionaryObject({}), 'li_attr': DictionaryObject({'id': 5}), 'icon': 'folder'})
>>> print node.jsonData()
{'text': 'a', 'state': {'opened': True}, 'id': 5, 'li_attr': {'id': 5}, 'icon': 'folder'}

>>> import jstree
>>> paths = [jstree.Path("editor/2012-07/31/.classpath", 1), jstree.Path("editor/2012-07/31/.project", 2)]
>>> print jstree.JSTree(paths).pretty()
/
  editor/
    2012-07/
      31/
        .classpath
        .project

>>> import jstree
>>> paths = [jstree.Path("editor/2012-07/31/.classpath", 1), jstree.Path("editor/2012-07/31/.project", 2)]
>>> t = jstree.JSTree(paths)
>>> d = t.jsonData()
>>> print d
[{'data': 'editor', 'children': [{'data': '2012-07', 'children': [{'data': '31', 'children': [{'data': '.classpath', 'metadata': {'id': 1}}, {'data': '.project', 'metadata': {'id': 2}}]}]}]}]
>>> print d[0]['children'][0]['children'][0]['children'][1]
{'data': '.project', 'metadata': {'id': 2}}
>>> print d[0]['children'][0]['children'][0]['children'][1]['data']
.project
>>> print d[0]['children'][0]['children'][0]['children'][1]['metadata']['id']
2
You can’t perform that action at this time.