方法

core functionality


destroy ()

destroy an instance

keep_htmlBoolean if not set to true the container will be emptied, otherwise the current DOM elements will be kept intact
_create_prototype_node ()

Create a prototype node

ReturnsDOMElement
get_container ()

returns the jQuery extended instance container

ReturnsjQuery
get_node (obj[, as_dom])

get the JSON representation of a node (or the actual jQuery extended DOM node) by using any input (child DOM element, ID string, selector, etc)

objmixed
as_domBoolean
ReturnsObject jQuery
get_path (obj[, glue, ids])

get the path to a node, either consisting of node texts, or of node IDs, optionally glued together (otherwise an array)

objmixed the node
glueString if you want the path as a string - pass the glue here (for example '/'), if a falsy value is supplied here, an array is returned
idsBoolean if set to true build the path using ID, otherwise node text is used
Returnsmixed
get_next_dom (obj[, strict])

get the next visible node that is below the obj node. If strict is set to true only sibling nodes are returned.

objmixed
strictBoolean
ReturnsjQuery
get_prev_dom (obj[, strict])

get the previous visible node that is above the obj node. If strict is set to true only sibling nodes are returned.

objmixed
strictBoolean
ReturnsjQuery
get_parent (obj)

get the parent ID of a node

objmixed
ReturnsString
get_children_dom (obj)

get a jQuery collection of all the children of a node (node must be rendered), returns false on error

objmixed
ReturnsjQuery
is_parent (obj)

checks if a node has children

objmixed
ReturnsBoolean
is_loaded (obj)

checks if a node is loaded (its children are available)

objmixed
ReturnsBoolean
is_loading (obj)

check if a node is currently loading (fetching children)

objmixed
ReturnsBoolean
is_open (obj)

check if a node is opened

objmixed
ReturnsBoolean
is_closed (obj)

check if a node is in a closed state

objmixed
ReturnsBoolean
is_leaf (obj)

check if a node has no children

objmixed
ReturnsBoolean
load_node (obj[, callback])

loads a node (fetches its children using the core.data setting). Multiple nodes can be passed to by using an array.

objmixed
callbackfunction a function to be executed once loading is complete, the function is executed in the instance's scope and receives two arguments - the node and a boolean status
ReturnsBoolean
Triggersload_node.jstree
load_all ([obj, callback])

loads all unloaded nodes

objmixed the node to load recursively, omit to load all nodes in the tree
callbackfunction a function to be executed once loading all the nodes is complete,
Triggersload_all.jstree
redraw ([full])

redraws all nodes that need to be redrawn or optionally - the whole tree

fullBoolean if set to true all nodes are redrawn.
open_node (obj[, callback, animation])

opens a node, revealing its children. If the node is not loaded it will be loaded and opened once ready.

objmixed the node to open
callbackFunction a function to execute once the node is opened
animationNumber the animation duration in milliseconds when opening the node (overrides the core.animation setting). Use false for no animation.
Triggersopen_node.jstree after_open.jstree before_open.jstree
close_node (obj[, animation])

closes a node, hiding its children

objmixed the node to close
animationNumber the animation duration in milliseconds when closing the node (overrides the core.animation setting). Use false for no animation.
Triggersclose_node.jstree after_close.jstree
toggle_node (obj)

toggles a node - closing it if it is open, opening it if it is closed

objmixed the node to toggle
open_all ([obj, animation, original_obj])

opens all nodes within a node (or the tree), revealing their children. If the node is not loaded it will be loaded and opened once ready.

objmixed the node to open recursively, omit to open all nodes in the tree
animationNumber the animation duration in milliseconds when opening the nodes, the default is no animation
referencejQuery to the node that started the process (internal use)
Triggersopen_all.jstree
close_all ([obj, animation])

closes all nodes within a node (or the tree), revealing their children

objmixed the node to close recursively, omit to close all nodes in the tree
animationNumber the animation duration in milliseconds when closing the nodes, the default is no animation
Triggersclose_all.jstree
is_disabled (obj)

checks if a node is disabled (not selectable)

objmixed
ReturnsBoolean
enable_node (obj)

enables a node - so that it can be selected

objmixed the node to enable
Triggersenable_node.jstree
disable_node (obj)

disables a node - so that it can not be selected

objmixed the node to disable
Triggersdisable_node.jstree
is_hidden (obj)

determines if a node is hidden

objmixed the node
hide_node (obj)

hides a node - it is still in the structure but will not be visible

objmixed the node to hide
skip_redrawBoolean internal parameter controlling if redraw is called
Triggershide_node.jstree
show_node (obj)

shows a node

objmixed the node to show
skip_redrawBoolean internal parameter controlling if redraw is called
Triggersshow_node.jstree
hide_all ()

hides all nodes

Triggershide_all.jstree
show_all ()

shows all nodes

Triggersshow_all.jstree
select_node (obj[, supress_event, prevent_open])

select a node

objmixed an array can be used to select multiple nodes
supress_eventBoolean if set to true the changed.jstree event won't be triggered
prevent_openBoolean if set to true parents of the selected node won't be opened
Triggersselect_node.jstree changed.jstree
deselect_node (obj[, supress_event])

deselect a node

objmixed an array can be used to deselect multiple nodes
supress_eventBoolean if set to true the changed.jstree event won't be triggered
Triggersdeselect_node.jstree changed.jstree
select_all ([supress_event])

select all nodes in the tree

supress_eventBoolean if set to true the changed.jstree event won't be triggered
Triggersselect_all.jstree changed.jstree
deselect_all ([supress_event])

deselect all selected nodes

supress_eventBoolean if set to true the changed.jstree event won't be triggered
Triggersdeselect_all.jstree changed.jstree
is_selected (obj)

checks if a node is selected

objmixed
ReturnsBoolean
get_selected ([full])

get an array of all selected nodes

fullmixed if set to true the returned array will consist of the full node objects, otherwise - only IDs will be returned
ReturnsArray
get_top_selected ([full])

get an array of all top level selected nodes (ignoring children of selected nodes)

fullmixed if set to true the returned array will consist of the full node objects, otherwise - only IDs will be returned
ReturnsArray
get_bottom_selected ([full])

get an array of all bottom level selected nodes (ignoring selected parents)

fullmixed if set to true the returned array will consist of the full node objects, otherwise - only IDs will be returned
ReturnsArray
refresh ()

refreshes the tree - all nodes are reloaded with calls to load_node.

skip_loadingBoolean an option to skip showing the loading indicator
forget_stateMixed if set to true state will not be reapplied, if set to a function (receiving the current state as argument) the result of that function will be used as state
Triggersrefresh.jstree
refresh_node (obj)

refreshes a node in the tree (reload its children) all opened nodes inside that node are reloaded with calls to load_node.

objmixed the node
Triggersrefresh_node.jstree
set_id (obj, id)

set (change) the ID of a node

objmixed the node
idString the new ID
ReturnsBoolean
Triggersset_id.jstree
get_text (obj)

get the text value of a node

objmixed the node
ReturnsString
get_json ([obj, options])

gets a JSON representation of a node (or the whole tree)

objmixed
optionsObject
options.no_stateBoolean do not return state information
options.no_idBoolean do not return ID
options.no_childrenBoolean do not include children
options.no_dataBoolean do not include node data
options.no_li_attrBoolean do not include LI attributes
options.no_a_attrBoolean do not include A attributes
options.flatBoolean return flat JSON instead of nested
ReturnsObject
create_node ([par, node, pos, callback, is_loaded])

create a new node (do not confuse with load_node)

parmixed the parent node (to create a root node use either "#" (string) or null)
nodemixed the data for the new node (a valid JSON object, or a simple string with the name)
posmixed the index at which to insert the node, "first" and "last" are also supported, default is "last"
callbackFunction a function to be called once the node is created
is_loadedBoolean internal argument indicating if the parent node was succesfully loaded
ReturnsString the ID of the newly create node
Triggersmodel.jstree create_node.jstree
rename_node (obj, val)

set the text value of a node

objmixed the node, you can pass an array to rename multiple nodes to the same name
valString the new text value
ReturnsBoolean
Triggersrename_node.jstree
delete_node (obj)

remove a node

objmixed the node, you can pass an array to delete multiple nodes
ReturnsBoolean
Triggersdelete_node.jstree
last_error ()

get the last error

ReturnsObject
move_node (obj, par[, pos, callback, is_loaded])

move a node to a new parent

objmixed the node to move, pass an array to move multiple nodes
parmixed the new parent
posmixed the position to insert at (besides integer values, "first" and "last" are supported, as well as "before" and "after"), defaults to integer 0
callbackfunction a function to call once the move is completed, receives 3 arguments - the node, the new parent and the position
is_loadedBoolean internal parameter indicating if the parent node has been loaded
skip_redrawBoolean internal parameter indicating if the tree should be redrawn
instanceBoolean internal parameter indicating if the node comes from another instance
Triggersmove_node.jstree
copy_node (obj, par[, pos, callback, is_loaded])

copy a node to a new parent

objmixed the node to copy, pass an array to copy multiple nodes
parmixed the new parent
posmixed the position to insert at (besides integer values, "first" and "last" are supported, as well as "before" and "after"), defaults to integer 0
callbackfunction a function to call once the move is completed, receives 3 arguments - the node, the new parent and the position
is_loadedBoolean internal parameter indicating if the parent node has been loaded
skip_redrawBoolean internal parameter indicating if the tree should be redrawn
instanceBoolean internal parameter indicating if the node comes from another instance
Triggersmodel.jstree copy_node.jstree
cut (obj)

cut a node (a later call to paste(obj) would move the node)

objmixed multiple objects can be passed using an array
Triggerscut.jstree
copy (obj)

copy a node (a later call to paste(obj) would copy the node)

objmixed multiple objects can be passed using an array
Triggerscopy.jstree
get_buffer ()

get the current buffer (any nodes that are waiting for a paste operation)

ReturnsObject an object consisting of mode ("copy_node" or "move_node"), node (an array of objects) and inst (the instance)
can_paste ()

check if there is something in the buffer to paste

ReturnsBoolean
paste (obj[, pos])

copy or move the previously cut or copied nodes to a new parent

objmixed the new parent
posmixed the position to insert at (besides integer, "first" and "last" are supported), defaults to integer 0
Triggerspaste.jstree
clear_buffer ()

clear the buffer of previously copied or cut nodes

Triggersclear_buffer.jstree
edit (obj[, default_text, callback])

put a node in edit mode (input field to rename the node)

objmixed
default_textString the text to populate the input with (if omitted or set to a non-string value the node's text value is used)
callbackFunction a function to be called once the text box is blurred, it is called in the instance's scope and receives the node, a status parameter (true if the rename is successful, false otherwise), a boolean indicating if the user cancelled the edit and the original unescaped value provided by the user. You can also access the node's title using .text
set_theme (theme_name[, theme_url])

changes the theme

theme_nameString the name of the new theme to apply
theme_urlmixed the location of the CSS file for this theme. Omit or set to false if you manually included the file. Set to true to autoload from the core.themes.dir directory.
Triggersset_theme.jstree
get_theme ()

gets the name of the currently applied theme name

ReturnsString
set_theme_variant (variant_name)

changes the theme variant (if the theme has variants)

variant_nameString Boolean the variant to apply (if false is used the current variant is removed)
show_stripes ()

shows a striped background on the container (if the theme supports it)

hide_stripes ()

hides the striped background on the container

toggle_stripes ()

toggles the striped background on the container

show_dots ()

shows the connecting dots (if the theme supports it)

hide_dots ()

hides the connecting dots

toggle_dots ()

toggles the connecting dots

show_icons ()

show the node icons

hide_icons ()

hide the node icons

toggle_icons ()

toggle the node icons

hide_ellipsis ()

hide the node ellipsis

set_icon (obj, icon)

set the node icon for a node

objmixed
iconString the new icon - can be a path to an icon or a className, if using an image that is in the current directory use a ./ prefix, otherwise it will be detected as a class
get_icon (obj)

get the node icon for a node

objmixed
ReturnsString
hide_icon (obj)

hide the icon on an individual node

objmixed
show_icon (obj)

show the icon on an individual node

objmixed

Checkbox plugin


This plugin renders checkbox icons in front of each node, making multiple selection much easier.

It also supports tri-state behavior, meaning that if a node has a few of its children checked it will be rendered as undetermined, and state will be propagated up.

get_undetermined ([full])

get an array of all nodes whose state is "undetermined"

fullboolean if set to true the returned array will consist of the full node objects, otherwise - only IDs will be returned
ReturnsArray
show_checkboxes ()

show the node checkbox icons

hide_checkboxes ()

hide the node checkbox icons

toggle_checkboxes ()

toggle the node icons

is_undetermined (obj)

checks if a node is in an undetermined state

objmixed
ReturnsBoolean
disable_checkbox (obj)

disable a node's checkbox

objmixed an array can be used too
Triggersdisable_checkbox.jstree
enable_checkbox (obj)

enable a node's checkbox

objmixed an array can be used too
Triggersenable_checkbox.jstree
get_checked_descendants (obj)

Gets ids of nodes selected in branch (of tree) specified by id (does not include the node specified by id)

idstring the node ID
ReturnsArray array of IDs
check_node (obj)

check a node (only if tie_selection in checkbox settings is false, otherwise select_node will be called internally)

objmixed an array can be used to check multiple nodes
Triggerscheck_node.jstree
uncheck_node (obj)

uncheck a node (only if tie_selection in checkbox settings is false, otherwise deselect_node will be called internally)

objmixed an array can be used to uncheck multiple nodes
Triggersuncheck_node.jstree
check_all ()

checks all nodes in the tree (only if tie_selection in checkbox settings is false, otherwise select_all will be called internally)

Triggerscheck_all.jstree changed.jstree
uncheck_all ()

uncheck all checked nodes (only if tie_selection in checkbox settings is false, otherwise deselect_all will be called internally)

Triggersuncheck_all.jstree
is_checked (obj)

checks if a node is checked (if tie_selection is on in the settings this function will return the same as is_selected)

objmixed
ReturnsBoolean
get_checked ([full])

get an array of all checked nodes (if tie_selection is on in the settings this function will return the same as get_selected)

fullmixed if set to true the returned array will consist of the full node objects, otherwise - only IDs will be returned
ReturnsArray
get_top_checked ([full])

get an array of all top level checked nodes (ignoring children of checked nodes) (if tie_selection is on in the settings this function will return the same as get_top_selected)

fullmixed if set to true the returned array will consist of the full node objects, otherwise - only IDs will be returned
ReturnsArray
get_bottom_checked ([full])

get an array of all bottom level checked nodes (ignoring selected parents) (if tie_selection is on in the settings this function will return the same as get_bottom_selected)

fullmixed if set to true the returned array will consist of the full node objects, otherwise - only IDs will be returned
ReturnsArray

Contextmenu plugin


Shows a context menu when a node is right-clicked.

show_contextmenu (obj[, x, y])

prepare and show the context menu for a node

objmixed the node
xNumber the x-coordinate relative to the document to show the menu at
yNumber the y-coordinate relative to the document to show the menu at
eObject the event if available that triggered the contextmenu
Triggersshow_contextmenu.jstree

Adds search functionality to jsTree.

used to search the tree nodes for a given string

strString the search string
skip_asyncBoolean if set to true server will not be queried even if configured
show_only_matchesBoolean if set to true only matching nodes will be shown (keep in mind this can be very slow on large trees or old browsers)
insidemixed an optional node to whose children to limit the search
appendBoolean if set to true the results of this search are appended to the previous search
Triggerssearch.jstree

used to clear the last search (removes classes and shows all nodes if filtering is on)

Triggersclear_search.jstree

State plugin


Saves the state of the tree (selected nodes, opened nodes) on the user's computer using available options (localStorage, cookies, etc)

save_state ()

save the state

restore_state ()

restore the state from the user's computer

clear_state ()

clear the state on the user's computer

Types plugin


Makes it possible to add predefined types for groups of nodes, which make it possible to easily control nesting rules and icon for each group.

get_rules (obj)

used to retrieve the type settings object for a node

objmixed the node to find the rules for
ReturnsObject
get_type (obj[, rules])

used to retrieve the type string or settings object for a node

objmixed the node to find the rules for
rulesBoolean if set to true instead of a string the settings object will be returned
ReturnsString Object
set_type (obj, type)

used to change a node's type

objmixed the node to change
typeString the new type