方法
core functionality
destroy ()
destroy an instance
keep_html | Boolean 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
Returns | DOMElement |
get_container ()
returns the jQuery extended instance container
Returns | jQuery |
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)
obj | mixed |
as_dom | Boolean |
Returns | Object 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)
obj | mixed the node |
glue | String 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 |
ids | Boolean if set to true build the path using ID, otherwise node text is used |
Returns | mixed |
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.
obj | mixed |
strict | Boolean |
Returns | jQuery |
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.
obj | mixed |
strict | Boolean |
Returns | jQuery |
get_parent (obj)
get the parent ID of a node
obj | mixed |
Returns | String |
get_children_dom (obj)
get a jQuery collection of all the children of a node (node must be rendered), returns false on error
obj | mixed |
Returns | jQuery |
is_parent (obj)
checks if a node has children
obj | mixed |
Returns | Boolean |
is_loaded (obj)
checks if a node is loaded (its children are available)
obj | mixed |
Returns | Boolean |
is_loading (obj)
check if a node is currently loading (fetching children)
obj | mixed |
Returns | Boolean |
is_open (obj)
check if a node is opened
obj | mixed |
Returns | Boolean |
is_closed (obj)
check if a node is in a closed state
obj | mixed |
Returns | Boolean |
is_leaf (obj)
check if a node has no children
obj | mixed |
Returns | Boolean |
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.
obj | mixed |
callback | function 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 |
Returns | Boolean |
Triggers | load_node.jstree |
load_all ([obj, callback])
loads all unloaded nodes
obj | mixed the node to load recursively, omit to load all nodes in the tree |
callback | function a function to be executed once loading all the nodes is complete, |
Triggers | load_all.jstree |
redraw ([full])
redraws all nodes that need to be redrawn or optionally - the whole tree
full | Boolean 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.
obj | mixed the node to open |
callback | Function a function to execute once the node is opened |
animation | Number the animation duration in milliseconds when opening the node (overrides the core.animation setting). Use false for no animation. |
Triggers | open_node.jstree after_open.jstree before_open.jstree |
close_node (obj[, animation])
closes a node, hiding its children
obj | mixed the node to close |
animation | Number the animation duration in milliseconds when closing the node (overrides the core.animation setting). Use false for no animation. |
Triggers | close_node.jstree after_close.jstree |
toggle_node (obj)
toggles a node - closing it if it is open, opening it if it is closed
obj | mixed 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.
obj | mixed the node to open recursively, omit to open all nodes in the tree |
animation | Number the animation duration in milliseconds when opening the nodes, the default is no animation |
reference | jQuery to the node that started the process (internal use) |
Triggers | open_all.jstree |
close_all ([obj, animation])
closes all nodes within a node (or the tree), revealing their children
obj | mixed the node to close recursively, omit to close all nodes in the tree |
animation | Number the animation duration in milliseconds when closing the nodes, the default is no animation |
Triggers | close_all.jstree |
is_disabled (obj)
checks if a node is disabled (not selectable)
obj | mixed |
Returns | Boolean |
enable_node (obj)
enables a node - so that it can be selected
obj | mixed the node to enable |
Triggers | enable_node.jstree |
disable_node (obj)
disables a node - so that it can not be selected
obj | mixed the node to disable |
Triggers | disable_node.jstree |
is_hidden (obj)
determines if a node is hidden
obj | mixed the node |
hide_node (obj)
hides a node - it is still in the structure but will not be visible
obj | mixed the node to hide |
skip_redraw | Boolean internal parameter controlling if redraw is called |
Triggers | hide_node.jstree |
show_node (obj)
shows a node
obj | mixed the node to show |
skip_redraw | Boolean internal parameter controlling if redraw is called |
Triggers | show_node.jstree |
hide_all ()
hides all nodes
Triggers | hide_all.jstree |
show_all ()
shows all nodes
Triggers | show_all.jstree |
select_node (obj[, supress_event, prevent_open])
select a node
obj | mixed an array can be used to select multiple nodes |
supress_event | Boolean if set to true the changed.jstree event won't be triggered |
prevent_open | Boolean if set to true parents of the selected node won't be opened |
Triggers | select_node.jstree changed.jstree |
deselect_node (obj[, supress_event])
deselect a node
obj | mixed an array can be used to deselect multiple nodes |
supress_event | Boolean if set to true the changed.jstree event won't be triggered |
Triggers | deselect_node.jstree changed.jstree |
select_all ([supress_event])
select all nodes in the tree
supress_event | Boolean if set to true the changed.jstree event won't be triggered |
Triggers | select_all.jstree changed.jstree |
deselect_all ([supress_event])
deselect all selected nodes
supress_event | Boolean if set to true the changed.jstree event won't be triggered |
Triggers | deselect_all.jstree changed.jstree |
is_selected (obj)
checks if a node is selected
obj | mixed |
Returns | Boolean |
get_selected ([full])
get an array of all selected nodes
full | mixed if set to true the returned array will consist of the full node objects, otherwise - only IDs will be returned |
Returns | Array |
get_top_selected ([full])
get an array of all top level selected nodes (ignoring children of selected nodes)
full | mixed if set to true the returned array will consist of the full node objects, otherwise - only IDs will be returned |
Returns | Array |
get_bottom_selected ([full])
get an array of all bottom level selected nodes (ignoring selected parents)
full | mixed if set to true the returned array will consist of the full node objects, otherwise - only IDs will be returned |
Returns | Array |
refresh ()
refreshes the tree - all nodes are reloaded with calls to load_node.
skip_loading | Boolean an option to skip showing the loading indicator |
forget_state | Mixed 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 |
Triggers | refresh.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.
obj | mixed the node |
Triggers | refresh_node.jstree |
set_id (obj, id)
set (change) the ID of a node
obj | mixed the node |
id | String the new ID |
Returns | Boolean |
Triggers | set_id.jstree |
get_text (obj)
get the text value of a node
obj | mixed the node |
Returns | String |
get_json ([obj, options])
gets a JSON representation of a node (or the whole tree)
obj | mixed |
options | Object |
options.no_state | Boolean do not return state information |
options.no_id | Boolean do not return ID |
options.no_children | Boolean do not include children |
options.no_data | Boolean do not include node data |
options.no_li_attr | Boolean do not include LI attributes |
options.no_a_attr | Boolean do not include A attributes |
options.flat | Boolean return flat JSON instead of nested |
Returns | Object |
create_node ([par, node, pos, callback, is_loaded])
create a new node (do not confuse with load_node)
par | mixed the parent node (to create a root node use either "#" (string) or null) |
node | mixed the data for the new node (a valid JSON object, or a simple string with the name) |
pos | mixed the index at which to insert the node, "first" and "last" are also supported, default is "last" |
callback | Function a function to be called once the node is created |
is_loaded | Boolean internal argument indicating if the parent node was succesfully loaded |
Returns | String the ID of the newly create node |
Triggers | model.jstree create_node.jstree |
rename_node (obj, val)
set the text value of a node
obj | mixed the node, you can pass an array to rename multiple nodes to the same name |
val | String the new text value |
Returns | Boolean |
Triggers | rename_node.jstree |
delete_node (obj)
remove a node
obj | mixed the node, you can pass an array to delete multiple nodes |
Returns | Boolean |
Triggers | delete_node.jstree |
last_error ()
get the last error
Returns | Object |
move_node (obj, par[, pos, callback, is_loaded])
move a node to a new parent
obj | mixed the node to move, pass an array to move multiple nodes |
par | mixed the new parent |
pos | mixed the position to insert at (besides integer values, "first" and "last" are supported, as well as "before" and "after"), defaults to integer 0 |
callback | function a function to call once the move is completed, receives 3 arguments - the node, the new parent and the position |
is_loaded | Boolean internal parameter indicating if the parent node has been loaded |
skip_redraw | Boolean internal parameter indicating if the tree should be redrawn |
instance | Boolean internal parameter indicating if the node comes from another instance |
Triggers | move_node.jstree |
copy_node (obj, par[, pos, callback, is_loaded])
copy a node to a new parent
obj | mixed the node to copy, pass an array to copy multiple nodes |
par | mixed the new parent |
pos | mixed the position to insert at (besides integer values, "first" and "last" are supported, as well as "before" and "after"), defaults to integer 0 |
callback | function a function to call once the move is completed, receives 3 arguments - the node, the new parent and the position |
is_loaded | Boolean internal parameter indicating if the parent node has been loaded |
skip_redraw | Boolean internal parameter indicating if the tree should be redrawn |
instance | Boolean internal parameter indicating if the node comes from another instance |
Triggers | model.jstree copy_node.jstree |
cut (obj)
cut a node (a later call to paste(obj) would move the node)
obj | mixed multiple objects can be passed using an array |
Triggers | cut.jstree |
copy (obj)
copy a node (a later call to paste(obj) would copy the node)
obj | mixed multiple objects can be passed using an array |
Triggers | copy.jstree |
get_buffer ()
get the current buffer (any nodes that are waiting for a paste operation)
Returns | Object 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
Returns | Boolean |
paste (obj[, pos])
copy or move the previously cut or copied nodes to a new parent
obj | mixed the new parent |
pos | mixed the position to insert at (besides integer, "first" and "last" are supported), defaults to integer 0 |
Triggers | paste.jstree |
clear_buffer ()
clear the buffer of previously copied or cut nodes
Triggers | clear_buffer.jstree |
edit (obj[, default_text, callback])
put a node in edit mode (input field to rename the node)
obj | mixed |
default_text | String the text to populate the input with (if omitted or set to a non-string value the node's text value is used) |
callback | Function 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_name | String the name of the new theme to apply |
theme_url | mixed 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. |
Triggers | set_theme.jstree |
get_theme ()
gets the name of the currently applied theme name
Returns | String |
set_theme_variant (variant_name)
changes the theme variant (if the theme has variants)
variant_name | String 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
obj | mixed |
icon | String 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
obj | mixed |
Returns | String |
hide_icon (obj)
hide the icon on an individual node
obj | mixed |
show_icon (obj)
show the icon on an individual node
obj | mixed |
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"
full | boolean if set to true the returned array will consist of the full node objects, otherwise - only IDs will be returned |
Returns | Array |
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
obj | mixed |
Returns | Boolean |
disable_checkbox (obj)
disable a node's checkbox
obj | mixed an array can be used too |
Triggers | disable_checkbox.jstree |
enable_checkbox (obj)
enable a node's checkbox
obj | mixed an array can be used too |
Triggers | enable_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)
id | string the node ID |
Returns | Array 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)
obj | mixed an array can be used to check multiple nodes |
Triggers | check_node.jstree |
uncheck_node (obj)
uncheck a node (only if tie_selection in checkbox settings is false, otherwise deselect_node will be called internally)
obj | mixed an array can be used to uncheck multiple nodes |
Triggers | uncheck_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)
Triggers | check_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)
Triggers | uncheck_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)
obj | mixed |
Returns | Boolean |
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)
full | mixed if set to true the returned array will consist of the full node objects, otherwise - only IDs will be returned |
Returns | Array |
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)
full | mixed if set to true the returned array will consist of the full node objects, otherwise - only IDs will be returned |
Returns | Array |
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)
full | mixed if set to true the returned array will consist of the full node objects, otherwise - only IDs will be returned |
Returns | Array |
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
obj | mixed the node |
x | Number the x-coordinate relative to the document to show the menu at |
y | Number the y-coordinate relative to the document to show the menu at |
e | Object the event if available that triggered the contextmenu |
Triggers | show_contextmenu.jstree |
Search plugin
Adds search functionality to jsTree.
search (str[, skip_async])
used to search the tree nodes for a given string
str | String the search string |
skip_async | Boolean if set to true server will not be queried even if configured |
show_only_matches | Boolean if set to true only matching nodes will be shown (keep in mind this can be very slow on large trees or old browsers) |
inside | mixed an optional node to whose children to limit the search |
append | Boolean if set to true the results of this search are appended to the previous search |
Triggers | search.jstree |
clear_search ()
used to clear the last search (removes classes and shows all nodes if filtering is on)
Triggers | clear_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
obj | mixed the node to find the rules for |
Returns | Object |
get_type (obj[, rules])
used to retrieve the type string or settings object for a node
obj | mixed the node to find the rules for |
rules | Boolean if set to true instead of a string the settings object will be returned |
Returns | String Object |
set_type (obj, type)
used to change a node's type
obj | mixed the node to change |
type | String the new type |