Fancytree Javascript Tree TreeTable 树介绍和使用
Fancytree是一个非常棒的Javascript控件,功能强大,文档健全。在做Javascript Tree控件选型时,主要基于以下几点选择了Fancytree
- 在Javascript Tree控件中,Fancytree的排名非常靠前,说明这个控件的用户使用量多、口碑好,当出现问题时在StackOverflow中容易找到答案
- 支持checkbox选择框
- 支持Tree Table
- checkbox选择框有三种状态,并可以disable掉checkbox选择框
- 丰富的示例展示和代码展示、详尽的介绍文档、丰富的事件支持
- 以下几方面虽然未使用到,但也是他很好的功能:节点可编辑、拖拽、过滤、全选、统计子节点、延迟加载、皮肤设置、事件钩子支持、右键菜单、树内部可加入多种控件
目录:
1. 前提条件---构建一颗Fancytree最基本的前提条件
2. 基础配置---完成一颗最基本的树结构所需做的配置
3. Fancytree所有配置项。名称、类型、介绍
4. Fancytree的Event(事件)预览、使用及介绍
5. Fancytree的属性、方法、参数及使用案例
6. FancytreeNode的属性、方法、参数及使用案例
7. 通过Javascript获取Fancytree、FancytreeNode对象和属性
8. Fancytree的事件钩子使用
9. 实用资料
1.前提条件---构建一颗Fancytree最基本的前提条件。
下面代码展示了需要构建一颗Fancytree的基本条件,如:Javascript、css、HTML元素(#tree)。特别注意,这里需要jquery-ui的js。
<head>
[...]
<!-- Include jQuery and jQuery UI -->
<script src="//code.jquery.com/jquery-1.11.3.min.js" type="text/javascript"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.min.js" type="text/javascript"></script>
<!-- Include Fancytree skin and library -->
<link href="fancytree/skin-win8/ui.fancytree.min.css" rel="stylesheet" type="text/css">
<script src="fancytree/jquery.fancytree-all.min.js" type="text/javascript"></script>
<!-- Initialize the tree when page is loaded -->
<script type="text/javascript">
$(function(){
// 具体如何给树传入数据请看第2条:基础配置
//Create the tree inside the <div id="tree"> element.
$("#tree").fancytree({ ... });
});
</script>
</head>
<body>
[...]
<!-- Define where the tree should appear -->
<div id="tree">...</div>
[...]
</body>
</html>
2.基础配置---完成一颗最基本的树结构所需做的配置
给Fancytree赋一个最基本的Json数据
<head>
[...]
<!-- Include jQuery and jQuery UI -->
<script src="//code.jquery.com/jquery-1.11.3.min.js" type="text/javascript"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.min.js" type="text/javascript"></script>
<!-- Include Fancytree skin and library -->
<link href="fancytree/skin-win8/ui.fancytree.min.css" rel="stylesheet" type="text/css">
<script src="fancytree/jquery.fancytree-all.min.js" type="text/javascript"></script>
<!-- Initialize the tree when page is loaded -->
<script type="text/javascript">
$(function(){
// 初始化数据内容,可以是json格式、文件、连接等。具体还有什么属性、方法、时间、钩子请看下面的内容
$("#tree").fancytree({
source: [ { "title": "Node 1", "key": "1" },
{"title": "Folder 2","key": "2","folder": true,"children": [
{ "title": "Node 2.1", "key": "3" },
{ "title": "Node 2.2", "key": "4" }
]}
]
}); });
</script>
</head>
<body>
[...]
<!-- Define where the tree should appear -->
<div id="tree">...</div>
[...]
</body>
</html>
3. Fancytree所有配置项。名称、类型、介绍
Name | Type | Description |
activeVisible | Boolean | Make sure that the active node is always visible, i.e. its parents are expanded (default: true). |
ajax | object | Default options for ajax requests |
aria | Boolean | (default: false) Add WAI-ARIA attributes to markup |
autoActivate | Boolean | Activate a node when focused with the keyboard (default: true) |
autoCollapse | Boolean | Automatically collapse all siblings, when a node is expanded (default: false). |
autoScroll | Boolean | Scroll node into visible area, when focused by keyboard (default: false). |
checkbox | Boolean | Display checkboxes to allow selection (default: false) |
clickFolderMode | Integer | Defines what happens, when the user click a folder node. |
1:activate, 2:expand, 3:activate and expand, 4:activate/dblclick expands (default: 4) | ||
debugLevel | Integer | 0..2 (null: use global setting $.ui.fancytree.debugInfo) |
defaultKey | function | callback(node) is called for ner nodes without a key. Must return a new unique key. (default null: generates default keys like that: "_" + counter) |
enableAspx | Boolean | Accept passing ajax data in a property named `d` (default: true). |
extensions | String[] | List of active extensions (default: []) |
focusOnSelect | Boolean | Set focus when node is checked by a mouse click (default: false) |
generateIds | Boolean | Add `id="..."` to node markup (default: false). |
icons | Boolean | Display node icons (default: true) |
idPrefix | String | (default: "ft_") |
imagePath | String | Path to a folder containing icons (default: null, using 'skin/' subdirectory). |
keyboard | Boolean | Support keyboard navigation (default: true). |
keyPathSeparator | String | (default: "/") |
minExpandLevel | Integer | 2: top-level nodes are not collapsible (default: 1) |
quicksearch | Boolean | navigate to next node by typing the first letters (default: false) |
scrollOfs: | object | optional margins for node.scrollIntoView() (default: {top: 0, bottom: 0}) |
scrollParent: | jQuery | scrollable container for node.scrollIntoView() (default: $container) |
selectMode | Integer | 1:single, 2:multi, 3:multi-hier (default: 2) |
source | any | Used to Initialize the tree. |
strings | object | Translation table |
tabbable | Boolean | Add tabindex='0' to container, so tree can be reached using TAB |
titlesTabbable | Boolean | Add tabindex='0' to node title span, so it can receive keyboard focus |
toggleEffect | object | Animation options, false:off (default: { effect: "blind", options: {direction: "vertical", scale: "box"}, duration: 200 }) |
4.Fancytree的Event(事件)预览、使用及介绍
<script type="text/javascript">
$.ui.fancytree.debugLevel = 1; // silence debug output
function logEvent(event, data, msg){
// var args = $.isArray(args) ? args.join(", ") :
msg = msg ? ": " + msg : "";
$.ui.fancytree.info("Event('" + event.type + "', node=" + data.node + ")" + msg);
}
$(function(){
$("#tree").fancytree({
checkbox: true,
// --- Tree events -------------------------------------------------
blurTree: function(event, data) {
logEvent(event, data);
},
create: function(event, data) {
logEvent(event, data);
},
init: function(event, data, flag) {
logEvent(event, data, "flag=" + flag);
},
focusTree: function(event, data) {
logEvent(event, data);
},
restore: function(event, data) {
logEvent(event, data);
},
// --- Node events -------------------------------------------------
activate: function(event, data) {
logEvent(event, data);
var node = data.node;
// acces node attributes
$("#echoActive").text(node.title);
if( !$.isEmptyObject(node.data) ){
// alert("custom node data: " + JSON.stringify(node.data));
}
},
beforeActivate: function(event, data) {
logEvent(event, data, "current state=" + data.node.isActive());
// return false to prevent default behavior (i.e. activation)
// return false;
},
beforeExpand: function(event, data) {
logEvent(event, data, "current state=" + data.node.isExpanded());
// return false to prevent default behavior (i.e. expanding or collapsing)
// return false;
},
beforeSelect: function(event, data) {
// console.log("select", event.originalEvent);
logEvent(event, data, "current state=" + data.node.isSelected());
// return false to prevent default behavior (i.e. selecting or deselecting)
// if( data.node.isFolder() ){
// return false;
// }
},
blur: function(event, data) {
logEvent(event, data);
$("#echoFocused").text("-");
},
click: function(event, data) {
logEvent(event, data, ", targetType=" + data.targetType);
// return false to prevent default behavior (i.e. activation, ...)
//return false;
},
collapse: function(event, data) {
logEvent(event, data);
},
createNode: function(event, data) {
// Optionally tweak data.node.span or bind handlers here
logEvent(event, data);
},
dblclick: function(event, data) {
logEvent(event, data);
// data.node.toggleSelect();
},
deactivate: function(event, data) {
logEvent(event, data);
$("#echoActive").text("-");
},
expand: function(event, data) {
logEvent(event, data);
},
focus: function(event, data) {
logEvent(event, data);
$("#echoFocused").text(data.node.title);
},
keydown: function(event, data) {
logEvent(event, data);
switch( event.which ) {
case 32: // [space]
data.node.toggleSelected();
return false;
}
},
keypress: function(event, data) {
// currently unused
logEvent(event, data);
},
lazyLoad: function(event, data) {
logEvent(event, data);
// return children or any other node source
data.result = {url: "ajax-sub2.json"};
// data.result = [
// {title: "A Lazy node", lazy: true},
// {title: "Another node", selected: true}
// ];
},
loadChildren: function(event, data) {
logEvent(event, data);
},
loadError: function(event, data) {
logEvent(event, data);
},
postProcess: function(event, data) {
logEvent(event, data);
// either modify the ajax response directly
data.response[0].title += " - hello from postProcess";
// or setup and return a new response object
// data.result = [{title: "set by postProcess"}];
},
removeNode: function(event, data) {
// Optionally release resources
logEvent(event, data);
},
renderNode: function(event, data) {
// Optionally tweak data.node.span
// $(data.node.span).text(">>" + data.node.title);
logEvent(event, data);
},
renderTitle: function(event, data) {
// NOTE: may be removed!
// When defined, must return a HTML string for the node title
logEvent(event, data);
// return "new title";
},
select: function(event, data) {
logEvent(event, data, "current state=" + data.node.isSelected());
var s = data.tree.getSelectedNodes().join(", ");
$("#echoSelected").text(s);
}
}).bind("fancytreeactivate", function(event, data){
// alternative way to bind to 'activate' event
// logEvent(event, data);
}).on("mouseenter mouseleave", ".fancytree-title", function(event){
// Add a hover handler to all node titles (using event delegation)
var node = $.ui.fancytree.getNode(event);
node.info(event.type);
});
$("#btnSelect").click(function(event){
var node = $("#tree").fancytree("getActiveNode");
node.setSelected( !node.isSelected() );
});
$("#btnRemove").click(function(event){
var node = $("#tree").fancytree("getActiveNode");
node.remove();
});
});
</script>
Name | Type | Description |
activate | function | `data.node` was activated |
beforeActivate | function | Return `false` to prevent default processing |
beforeExpand | function | Return `false` to prevent default processing |
beforeSelect | function | Return `false` to prevent default processing |
blur | function | `data.node` lost keyboard focus |
blurTree | function | `data.tree` lost keyboard focus |
click | function | `data.node` was clicked. `data.targetType` contains the region ("title", "expander", ...). Return `false` to prevent default processing, i.e. activating, etc. |
collapse | function | `data.node` was collapsed |
create | function | Widget was created (called only once, even if re-initialized). |
createNode | function | Allow tweaking and binding, after node was created for the first time (NOTE: this event is only available as callback, but not for bind()) |
dblclick | function | `data.node` was double-clicked. `data.targetType` contains the region ("title", "expander", ...). Return `false` to prevent default processing, i.e. expanding, etc. |
deactivate | function | `data.node` was deactivated |
expand | function | `data.node` was expanded |
focus | function | `data.node` received keyboard focus |
focusTree | function | `data.tree` received keyboard focus |
init | function | Widget was (re-)initialized. |
keydown | function | `data.node` received key. `event.which` contains the key. Return `false` to prevent default processing, i.e. navigation. Call `data.result = "preventNav";` to prevent navigation but still allow default handling inside embedded input controls. |
keypress | function | (currently unused) |
lazyLoad | function | `data.node` is a lazy node that is expanded for the first time. The new child data must be returned in the `data.result` property (see `source` option for available formats). |
loadChildren | function | Node data was loaded, i.e. `node.nodeLoadChildren()` finished |
loadError | function | A load error occured. Return `false` to prevent default processing |
postProcess | function | Allows to modify the ajax response |
removeNode | function | `data.node` was removed (NOTE: this event is only available as callback, but not for bind()) |
renderColumns | function | (used by table extension) |
renderNode | function | Allow tweaking after node state was rendered (NOTE: this event is only available as callback, but not for bind()) |
renderTitle | function | Allow replacing the `<span class='fancytree-title'>` markup (NOTE: this event is only available as callback, but not for bind()) |
restore | function | ext-persist has expanded, selected, and activated the previous state |
select | function | `data.node` was selected |
5.Fancytree的属性、方法、参数及使用案例
Properties:
Type | Name | Description |
---|---|---|
FancytreeOptions | options |
|
FancytreeNode | rootNode |
|
FancytreeNode | activeNode |
|
FancytreeNode | focusNode |
|
jQueryObject | $div |
|
object | widget |
|
object | ext |
|
object | data |
|
object | options |
|
string | _id |
|
string | statusClassPropName |
|
string | ariaPropName |
|
string | nodeContainerAttrName |
|
string | $container |
|
FancytreeNode | lastSelectedNode |
Methods:
Return Type | Name and Arguments | Details | |
---|---|---|---|
FancytreeNode | activateKey(key)
Activate node with a given key and fire focus and activate events. A prevously activated node will be deactivated. If activeVisible option is set, all parents will be expanded as necessary. Pass key = false, to deactivate the current node only.
|
Details |
Activate node with a given key and fire focus and activate events.
A prevously activated node will be deactivated. |
$.Promise | applyPatch(patchList)
(experimental)
|
Details | (experimental) |
void | changeRefKey(oldRefKey, newRefKey)
[ext-clones] Replace a refKey with a new one.
|
Details | [ext-clones] Replace a refKey with a new one. |
void | clearCookies()
[ext-persist] Remove persistence cookies of the given type(s). Called like $("#tree").fancytree("getTree").clearCookies("active expanded focus selected");
|
Details |
[ext-persist] Remove persistence cookies of the given type(s). Called like $("#tree").fancytree("getTree").clearCookies("active expanded focus selected"); |
void | clearFilter()
[ext-filter] Reset the filter.
|
Details | [ext-filter] Reset the filter. |
integer | count()
Return the number of nodes.
|
Details | Return the number of nodes. |
void | debug(msg)
Write to browser console if debugLevel >= 2 (prepending tree name)
|
Details | Write to browser console if debugLevel >= 2 (prepending tree name) |
integer | filterBranches(filter, opts={autoExpand: false})
[ext-filter] Dimm or hide whole branches.
|
Details | [ext-filter] Dimm or hide whole branches. |
integer | filterNodes(filter, opts={autoExpand: false, leavesOnly: false})
[ext-filter] Dimm or hide nodes.
|
Details | [ext-filter] Dimm or hide nodes. |
FancytreeNode | findNextNode(match, startNode)
Find the next visible node that starts with `match`, starting at `startNode` and wrap-around at the end.
|
Details |
Find the next visible node that starts with `match`, starting at `startNode` and wrap-around at the end. |
void | generateFormElements(selected=true, active=true, opts)
Generate INPUT elements that can be submitted with html forms. In selectMode 3 only the topmost selected nodes are considered, unless `opts.stopOnParents: false` is passed.
|
Details |
Generate INPUT elements that can be submitted with html forms.
In selectMode 3 only the topmost selected nodes are considered, unless |
FancytreeNode | getActiveNode()
Return the currently active node or null.
|
Details | Return the currently active node or null. |
FancytreeNode | null | getFirstChild()
Return the first top level node if any (not the invisible root node).
|
Details | Return the first top level node if any (not the invisible root node). |
FancytreeNode | getFocusNode()
Return node that has keyboard focus or null.
|
Details | Return node that has keyboard focus or null. |
FancytreeNode | null | getNodeByKey(key, searchRoot)
Return node with a given key or null if not found.
|
Details | Return node with a given key or null if not found. |
FancytreeNode[] | null | getNodesByRef(refKey, rootNode)
[ext-clones] Return all nodes with a given refKey (null if not found).
|
Details | [ext-clones] Return all nodes with a given refKey (null if not found). |
void | getPersistData()
[ext-persist] Return persistence information from cookies Called like $("#tree").fancytree("getTree").getPersistData();
|
Details |
[ext-persist] Return persistence information from cookies
Called like |
FancytreeNode | getRootNode()
Return the invisible system root node.
|
Details | Return the invisible system root node. |
FancytreeNode[] | getSelectedNodes(stopOnParents=false)
Return an array of selected nodes.
|
Details | Return an array of selected nodes. |
boolean | hasFocus()
Return true if the tree control has keyboard focus
|
Details | Return true if the tree control has keyboard focus |
void | info(msg)
Write to browser console if debugLevel >= 1 (prepending tree name)
|
Details | Write to browser console if debugLevel >= 1 (prepending tree name) |
FancytreeNode | null | isEditing()
[ext-edit] Check if any node in this tree in edit mode.
|
Details | [ext-edit] Check if any node in this tree in edit mode. |
$.Promise | loadKeyPath(keyPathList, callback)
Make sure that a node with a given ID is loaded, by traversing - and loading - its parents. This method is ment for lazy hierarchies. A callback is executed for every node as we go.
|
Details |
Make sure that a node with a given ID is loaded, by traversing - and loading - its parents. This method is ment for lazy hierarchies. A callback is executed for every node as we go. |
void | reactivate()
Re-fire beforeActivate and activate events.
|
Details | Re-fire beforeActivate and activate events. |
$.Promise | reload(source)
Reload tree from source and return a promise.
|
Details | Reload tree from source and return a promise. |
void | render(force=false, deep=false)
Render tree (i.e. create DOM elements for all top-level nodes).
|
Details | Render tree (i.e. create DOM elements for all top-level nodes). |
void | setFocus(flag=true) |
Details | |
Array | object | toDict(includeRoot=false, callback(node))
Return all nodes as nested list of NodeData.
|
Details | Return all nodes as nested list of NodeData. |
boolean | visit(fn)
Call fn(node) for all nodes.
|
Details | Call fn(node) for all nodes. |
void | warn(msg)
Write warning to browser console (prepending tree info)
|
6.FancytreeNode的属性、方法、参数及使用案例
new FancytreeNode(parent, obj)
Parameters:
Name | Type | Description |
---|---|---|
parent |
FancytreeNode | |
obj |
NodeData |
Properties:
Type | Name | Description |
---|---|---|
Fancytree | tree |
The tree instance |
FancytreeNode | parent |
The parent node |
string | key |
Node id (must be unique inside the tree) |
string | title |
Display name (may contain HTML) |
object | data |
Contains all extra data that was passed on node creation |
FancytreeNode[] | null | undefined | children |
Array of child nodes. For lazy nodes, null or undefined means 'not yet loaded'. Use an empty array to define a node that has no children. |
boolean | expanded |
Use isExpanded(), setExpanded() to access this property. |
string | extraClasses |
Addtional CSS classes, added to the node's `<span>` |
boolean | folder |
Folder nodes have different default icons and click behavior. Note: Also non-folders may have children. |
string | statusNodeType |
null or type of temporarily generated system node like 'loading', or 'error'. |
boolean | lazy |
True if this node is loaded on demand, i.e. on first expansion. |
boolean | selected |
Use isSelected(), setSelected() to access this property. |
string | tooltip |
Alternative description used as hover banner |
Methods:
Return Type | Name and Arguments | Details | |
---|---|---|---|
FancytreeNode | addChildren(children, insertBefore)
Append (or insert) a list of child nodes.
|
Details | Append (or insert) a list of child nodes. |
FancytreeNode | addNode(node, mode=child)
Append or prepend a node, or append a child node. This a convenience function that calls addChildren()
|
Details |
Append or prepend a node, or append a child node.
This a convenience function that calls addChildren() |
FancytreeNode | appendSibling(node)
Append new node after this. This a convenience function that calls addNode(node, 'after')
|
Details |
Append new node after this.
This a convenience function that calls addNode(node, 'after') |
$.Promise | applyPatch(patch)
Modify existing child nodes.
|
Details | Modify existing child nodes. |
$.Promise | collapseSiblings()
Collapse all sibling nodes.
|
Details | Collapse all sibling nodes. |
FancytreeNode | copyTo(node, mode=child, map)
Copy this node as sibling or child of `node`.
|
Details | Copy this node as sibling or child of `node`. |
int | countChildren(deep=true)
Count direct and indirect children.
|
Details | Count direct and indirect children. |
void | debug(msg)
Write to browser console if debugLevel >= 2 (prepending node info)
|
Details | Write to browser console if debugLevel >= 2 (prepending node info) |
void | discard()
Deprecated.
|
Details | Deprecated. |
void | editCreateNode(mode='child', init)
[ext-edit] Create a new child or sibling node and start edit mode.
|
Details | [ext-edit] Create a new child or sibling node and start edit mode. |
void | editEnd(applyChanges=false)
[ext-edit] Stop inline editing.
|
Details | [ext-edit] Stop inline editing. |
void | editStart()
[ext-edit] Start inline editing of current node title.
|
Details | [ext-edit] Start inline editing of current node title. |
FancytreeNode[] | findAll(match)
Find all nodes that contain `match` in the title.
|
Details | Find all nodes that contain `match` in the title. |
FancytreeNode | findFirst(match)
Find first node that contains `match` in the title (not including self).
|
Details | Find first node that contains `match` in the title (not including self). |
void | fixSelection3AfterClick()
Fix selection status, after this node was (de)selected in multi-hier mode. This includes (de)selecting all children.
|
Details |
Fix selection status, after this node was (de)selected in multi-hier mode. This includes (de)selecting all children. |
void | fixSelection3FromEndNodes()
Fix selection status for multi-hier mode. Only end-nodes are considered to update the descendants branch and parents. Should be called after this node has loaded new children or after children have been modified using the API.
|
Details |
Fix selection status for multi-hier mode. Only end-nodes are considered to update the descendants branch and parents. Should be called after this node has loaded new children or after children have been modified using the API. |
void | fromDict(dict)
Update node data. If dict contains 'children', then also replace the hole sub tree.
|
Details |
Update node data. If dict contains 'children', then also replace the hole sub tree. |
FancytreeNode[] | undefined | getChildren()
Return the list of child nodes (undefined for unexpanded lazy nodes).
|
Details | Return the list of child nodes (undefined for unexpanded lazy nodes). |
FancytreeNode[] | null | getCloneList(includeSelf=false)
[ext-clones] Return a list of clone-nodes or null.
|
Details | [ext-clones] Return a list of clone-nodes or null. |
FancytreeNode | null | getFirstChild()
Return the first child node or null.
|
Details | Return the first child node or null. |
int | getIndex()
Return the 0-based child index.
|
Details | Return the 0-based child index. |
string | getIndexHier()
Return the hierarchical child index (1-based, e.g. '3.2.4').
|
Details | Return the hierarchical child index (1-based, e.g. '3.2.4'). |
string | getKeyPath(excludeSelf=false)
Return the parent keys separated by options.keyPathSeparator, e.g. "id_1/id_17/id_32".
|
Details | Return the parent keys separated by options.keyPathSeparator, e.g. "id_1/id_17/id_32". |
FancytreeNode | null | getLastChild()
Return the last child of this node or null.
|
Details | Return the last child of this node or null. |
int | getLevel()
Return node depth. 0: System root node, 1: visible top-level node, 2: first sub-level, ... .
|
Details | Return node depth. 0: System root node, 1: visible top-level node, 2: first sub-level, ... . |
FancytreeNode | null | getNextSibling()
Return the successor node (under the same parent) or null.
|
Details | Return the successor node (under the same parent) or null. |
FancytreeNode | null | getParent()
Return the parent node (null for the system root node).
|
Details | Return the parent node (null for the system root node). |
FancytreeNode[] | getParentList(includeRoot=false, includeSelf=false)
Return an array of all parent nodes (top-down).
|
Details | Return an array of all parent nodes (top-down). |
FancytreeNode | null | getPrevSibling()
Return the predecessor node (under the same parent) or null.
|
Details | Return the predecessor node (under the same parent) or null. |
boolean | undefined | hasChildren()
Return true if node has children. Return undefined if not sure, i.e. the node is lazy and not yet loaded).
|
Details | Return true if node has children. Return undefined if not sure, i.e. the node is lazy and not yet loaded). |
boolean | hasFocus()
Return true if node has keyboard focus.
|
Details | Return true if node has keyboard focus. |
void | info(msg)
Write to browser console if debugLevel >= 1 (prepending node info)
|
Details | Write to browser console if debugLevel >= 1 (prepending node info) |
boolean | isActive()
Return true if node is active (see also FancytreeNode#isSelected).
|
Details | Return true if node is active (see also FancytreeNode#isSelected). |
boolean | isChildOf(otherNode)
Return true if node is a direct child of otherNode.
|
Details | Return true if node is a direct child of otherNode. |
boolean | isClone()
[ext-clones] Return true if this node has at least another clone with same refKey.
|
Details | [ext-clones] Return true if this node has at least another clone with same refKey. |
boolean | isDescendantOf(otherNode)
Return true, if node is a direct or indirect sub node of otherNode.
|
Details | Return true, if node is a direct or indirect sub node of otherNode. |
Boolean | isEditing()
[ext-edit] Check if this node is in edit mode.
|
Details | [ext-edit] Check if this node is in edit mode. |
boolean | isExpanded()
Return true if node is expanded.
|
Details | Return true if node is expanded. |
boolean | isFirstSibling()
Return true if node is the first node of its parent's children.
|
Details | Return true if node is the first node of its parent's children. |
boolean | isFolder()
Return true if node is a folder, i.e. has the node.folder attribute set.
|
Details | Return true if node is a folder, i.e. has the node.folder attribute set. |
boolean | isLastSibling()
Return true if node is the last node of its parent's children.
|
Details | Return true if node is the last node of its parent's children. |
boolean | isLazy()
Return true if node is lazy (even if data was already loaded)
|
Details | Return true if node is lazy (even if data was already loaded) |
boolean | isLoaded()
Return true if node is lazy and loaded. For non-lazy nodes always return true.
|
Details | Return true if node is lazy and loaded. For non-lazy nodes always return true. |
boolean | isLoading()
Return true if children are currently beeing loaded, i.e. a Ajax request is pending.
|
Details | Return true if children are currently beeing loaded, i.e. a Ajax request is pending. |
boolean | isRootNode()
Return true if this is the (invisible) system root node.
|
Details | Return true if this is the (invisible) system root node. |
boolean | isSelected()
Return true if node is selected, i.e. has a checkmark set (see also FancytreeNode#isActive).
|
Details | Return true if node is selected, i.e. has a checkmark set (see also FancytreeNode#isActive). |
boolean | isStatusNode()
Return true if this node is a temporarily generated system node like 'loading', or 'error' (node.statusNodeType contains the type).
|
Details |
Return true if this node is a temporarily generated system node like 'loading', or 'error' (node.statusNodeType contains the type). |
boolean | isTopLevel()
Return true if this a top level node, i.e. a direct child of the (invisible) system root node.
|
Details | Return true if this a top level node, i.e. a direct child of the (invisible) system root node. |
boolean | isUndefined()
Return true if node is lazy and not yet loaded. For non-lazy nodes always return false.
|
Details | Return true if node is lazy and not yet loaded. For non-lazy nodes always return false. |
boolean | isVisible()
Return true if all parent nodes are expanded. Note: this does not check whether the node is scrolled into the visible part of the screen.
|
Details |
Return true if all parent nodes are expanded. Note: this does not check whether the node is scrolled into the visible part of the screen. |
void | lazyLoad()
Deprecated.
|
Details | Deprecated. |
$.Promise | load(forceReload=false)
Load all children of a lazy node if neccessary. The *expanded* state is maintained.
|
Details | Load all children of a lazy node if neccessary. The *expanded* state is maintained. |
$.Promise | makeVisible(opts)
Expand all parents and optionally scroll into visible area as neccessary. Promise is resolved, when lazy loading and animations are done.
|
Details |
Expand all parents and optionally scroll into visible area as neccessary. Promise is resolved, when lazy loading and animations are done. |
void | moveTo(targetNode, mode, map)
Move this node to targetNode.
|
Details | Move this node to targetNode. |
$.Promise | navigate(where, activate=true)
Set focus relative to this node and optionally activate.
|
Details | Set focus relative to this node and optionally activate. |
void | remove()
Remove this node (not allowed for system root).
|
Details | Remove this node (not allowed for system root). |
void | removeChild(childNode)
Remove childNode from list of direct children.
|
Details | Remove childNode from list of direct children. |
void | removeChildren()
Remove all child nodes and descendents. This converts the node into a leaf.
If this was a lazy node, it is still considered 'loaded'; call node.resetLazy() in order to trigger lazyLoad on next expand. |
Details |
Remove all child nodes and descendents. This converts the node into a leaf. If this was a lazy node, it is still considered 'loaded'; call node.resetLazy() in order to trigger lazyLoad on next expand. |
void | render(force=false, deep=false)
This method renders and updates all HTML markup that is required to display this node in its current state.
Note:
|
Details |
This method renders and updates all HTML markup that is required to display this node in its current state. Note:
|
void | renderStatus()
Update element's CSS classes according to node state.
|
Details | Update element's CSS classes according to node state. |
void | renderTitle()
Create HTML markup for the node's outer <span> (expander, checkbox, icon, and title).
|
Details | Create HTML markup for the node's outer <span> (expander, checkbox, icon, and title). |
boolean | reRegister(key, refKey)
[ext-clones] Update key and/or refKey for an existing node.
|
Details | [ext-clones] Update key and/or refKey for an existing node. |
void | resetLazy()
Remove all children, collapse, and set the lazy-flag, so that the lazyLoad event is triggered on next expand.
|
Details |
Remove all children, collapse, and set the lazy-flag, so that the lazyLoad event is triggered on next expand. |
void | scheduleAction(mode, ms)
Schedule activity for delayed execution (cancel any pending request). scheduleAction('cancel') will only cancel a pending request (if any).
|
Details |
Schedule activity for delayed execution (cancel any pending request). scheduleAction('cancel') will only cancel a pending request (if any). |
$.Promise | scrollIntoView(effects=false, options=null) |
Details | |
$.Promise | setActive(flag=true, opts)
Activate this node.
|
Details | Activate this node. |
$.Promise | setExpanded(flag=true, opts)
Expand or collapse this node. Promise is resolved, when lazy loading and animations are done.
|
Details | Expand or collapse this node. Promise is resolved, when lazy loading and animations are done. |
void | setFocus(flag=true)
Set keyboard focus to this node.
|
Details | Set keyboard focus to this node. |
void | setSelected(flag=true)
Select this node, i.e. check the checkbox.
|
Details | Select this node, i.e. check the checkbox. |
void | setStatus(status, message, details)
Mark a lazy node as 'error', 'loading', or 'ok'.
|
Details | Mark a lazy node as 'error', 'loading', or 'ok'. |
void | setTitle(title)
Rename this node.
|
Details | Rename this node. |
void | sortChildren(cmp, deep=false)
Sort child list by title.
|
Details | Sort child list by title. |
NodeData | toDict(recursive=false, callback)
Convert node (or whole branch) into a plain object. The result is compatible with node.addChildren().
|
Details |
Convert node (or whole branch) into a plain object.
The result is compatible with node.addChildren(). |
void | toggleExpanded()
Flip expanded status.
|
Details | Flip expanded status. |
void | toggleSelected()
Flip selection status.
|
Details | Flip selection status. |
boolean | visit(fn, includeSelf=false)
Call fn(node) for all child nodes.
Stop iteration, if fn() returns false. Skip current branch, if fn() returns "skip". Return false if iteration was stopped. |
Details |
Call fn(node) for all child nodes. Stop iteration, if fn() returns false. Skip current branch, if fn() returns "skip". Return false if iteration was stopped. |
$.Promise | visitAndLoad(fn, includeSelf=false)
Call fn(node) for all child nodes and recursively load lazy children.
Note: If you need this method, you probably should consider to review your architecture! Recursivley loading nodes is a perfect way for lazy programmers to flood the server with requests ;-) |
Details |
Call fn(node) for all child nodes and recursively load lazy children. Note: If you need this method, you probably should consider to review your architecture! Recursivley loading nodes is a perfect way for lazy programmers to flood the server with requests ;-) |
boolean | visitParents(fn, includeSelf=false)
Call fn(node) for all parent nodes, bottom-up, including invisible system root.
Stop iteration, if fn() returns false. Return false if iteration was stopped. |
Details |
Call fn(node) for all parent nodes, bottom-up, including invisible system root. Stop iteration, if fn() returns false. Return false if iteration was stopped. |
void | warn(msg)
Write warning to browser console (prepending node info)
|
Details |
7.通过Javascript获取Fancytree、FancytreeNode对象和属性
//获取Id为tree的Fancytree对象
$("#tree").fancytree("getTree") //获取tree的根节点
$("#tree").fancytree("getRootNode") //访问每个节点并把节点展开
$("#tree").fancytree("getRootNode").visit(function(node) {
node.setExpanded(true);
});
8.Fancytree的事件钩子使用
Fancytree_Hooks
Methods:
Return Type | Name and Arguments | Details | |
---|---|---|---|
void | nodeClick(ctx)
Default handling for mouse click events.
|
Details | Default handling for mouse click events. |
void | nodeCollapseSiblings(ctx, callOpts)
Collapse all other children of same parent.
|
Details | Collapse all other children of same parent. |
void | nodeDblclick(ctx)
Default handling for mouse douleclick events.
|
Details | Default handling for mouse douleclick events. |
void | nodeKeydown(ctx)
Default handling for mouse keydown events. NOTE: this may be called with node == null if tree (but no node) has focus.
|
Details |
Default handling for mouse keydown events.
NOTE: this may be called with node == null if tree (but no node) has focus. |
$.Promise | nodeLoadChildren(ctx, source)
Load child nodes (async).
|
Details | Load child nodes (async). |
void | nodeLoadKeyPath()
[Not Implemented]
|
Details | [Not Implemented] |
void | nodeRemoveChild(ctx, childNode)
Remove a single direct child of ctx.node.
|
Details | Remove a single direct child of ctx.node. |
void | nodeRemoveChildMarkup(ctx)
Remove HTML markup for all descendents of ctx.node.
|
Details | Remove HTML markup for all descendents of ctx.node. |
void | nodeRemoveChildren(ctx)
Remove all descendants of ctx.node.
|
Details | Remove all descendants of ctx.node. |
void | nodeRemoveMarkup(ctx)
Remove HTML markup for ctx.node and all its descendents.
|
Details | Remove HTML markup for ctx.node and all its descendents. |
void | nodeRender(ctx, force=false, deep=false, collapsed=false)
Create `<li><span>..</span> .. </li>` tags for this node. This method takes care that all HTML markup is created that is required to display this node in it's current state. Call this method to create new nodes, or after the strucuture was changed (e.g. after moving this node or adding/removing children) nodeRenderTitle() and nodeRenderStatus() are implied. Note: if a node was created/removed, nodeRender() must be called for the parent.< code>< li id='KEY' ftnode=NODE> <span class='fancytree-node fancytree-expanded fancytree-has-children fancytree-lastsib fancytree-exp-el fancytree-ico-e'> <span class="fancytree-expander"></span> <span class="fancytree-checkbox"></span> // only present in checkbox mode <span class="fancytree-icon"></span> <a href="#" class="fancytree-title"> Node 1 </a> </span> <ul> // only present if node has children <li id='KEY' ftnode=NODE> child1 ... </li> <li id='KEY' ftnode=NODE> child2 ... </li> </ul>< /li>< /code>
|
Details |
Create `<li><span>..</span> .. </li>` tags for this node.
This method takes care that all HTML markup is created that is required Call this method to create new nodes, or after the strucuture Note: if a node was created/removed, nodeRender() must be called for the |
void | nodeRenderStatus(ctx)
Update element classes according to node state.
|
Details | Update element classes according to node state. |
void | nodeRenderTitle(ctx, title)
Create HTML inside the node's outer <span> (i.e. expander, checkbox, icon, and title). nodeRenderStatus() is implied.
|
Details |
Create HTML inside the node's outer <span> (i.e. expander, checkbox, icon, and title). nodeRenderStatus() is implied. |
$.Promise | nodeSetActive(ctx, flag=true, opts)
Activate node. flag defaults to true. If flag is true, the node is activated (must be a synchronous operation) If flag is false, the node is deactivated (must be a synchronous operation)
|
Details |
Activate node. flag defaults to true. If flag is true, the node is activated (must be a synchronous operation) If flag is false, the node is deactivated (must be a synchronous operation) |
$.Promise | nodeSetExpanded(ctx, flag=true, opts)
Expand or collapse node, return Deferred.promise.
|
Details | Expand or collapse node, return Deferred.promise. |
void | nodeSetFocus(ctx, flag=true)
Focus or blur this node.
|
Details | Focus or blur this node. |
void | nodeSetSelected(ctx, flag=true)
(De)Select node, return new status (sync).
|
Details | (De)Select node, return new status (sync). |
void | nodeSetStatus(ctx, status, message, details)
Show node status (ok, loading, error) using styles and a dummy child node.
|
Details | Show node status (ok, loading, error) using styles and a dummy child node. |
void | nodeToggleExpanded(ctx) |
Details | |
void | nodeToggleSelected(ctx) |
Details | |
void | treeClear(ctx)
Remove all nodes.
|
Details | Remove all nodes. |
void | treeCreate(ctx)
Widget was created (called only once, even it re-initialized).
|
Details | Widget was created (called only once, even it re-initialized). |
void | treeDestroy(ctx)
Widget was destroyed.
|
Details | Widget was destroyed. |
void | treeInit(ctx)
Widget was (re-)initialized.
|
Details | Widget was (re-)initialized. |
void | treeLoad(ctx, source)
Parse Fancytree from source, as configured in the options.
|
Details | Parse Fancytree from source, as configured in the options. |
void | treeRegisterNode(ctx, add, node)
Node was inserted into or removed from the tree.
|
Details | Node was inserted into or removed from the tree. |
void | treeSetFocus(ctx, flag=true)
Widget got focus.
|
学习资料:
Github源码及介绍:https://github.com/mar10/fancytree/
在线示例、示例源码、Demo:http://wwwendt.de/tech/fancytree/demo/
基本功能示例介绍(用户指南),右侧分类介绍,Wiki:https://github.com/mar10/fancytree/wiki
最有用的详细API介绍,类、方法、属性、事件、钩子等等。点击右侧分类进入具体的介绍:http://wwwendt.de/tech/fancytree/doc/jsdoc/
Fancytree Javascript Tree TreeTable 树介绍和使用的更多相关文章
- 【数据结构】B-Tree, B+Tree, B*树介绍 转
[数据结构]B-Tree, B+Tree, B*树介绍 [摘要] 最近在看Mysql的存储引擎中索引的优化,神马是索引,支持啥索引.全是浮云,目前Mysql的MyISAM和InnoDB都支持B-Tre ...
- B-Tree, B+Tree, B*树介绍
[数据结构]B-Tree, B+Tree, B*树介绍 转 [数据结构]B-Tree, B+Tree, B*树介绍 [摘要] 最近在看Mysql的存储引擎中索引的优化,神马是索引,支持啥索引.全是 ...
- Fancytree Javascript Tree的入门使用
Fancytree Javascript Tree的入门使用 一.概念----是做什么的能干什么 Fancytree是一个Javascript控件,它依赖于: <script src=" ...
- Mysql B-Tree, B+Tree, B*树介绍
[摘要] 最近在看Mysql的存储引擎中索引的优化,神马是索引,支持啥索引.全是浮云,目前Mysql的MyISAM和InnoDB都支持B-Tree索引,InnoDB还支持B+Tree索引,Memory ...
- 【数据结构】B-Tree, B+Tree, B*树介绍
[摘要] 最近在看Mysql的存储引擎中索引的优化,神马是索引,支持啥索引.全是浮云,目前Mysql的MyISAM和InnoDB都支持B-Tree索引,InnoDB还支持B+Tree索引,Memory ...
- [转] Splay Tree(伸展树)
好久没写过了,比赛的时候就调了一个小时,差点悲剧,重新复习一下,觉得这个写的很不错.转自:here Splay Tree(伸展树) 二叉查找树(Binary Search Tree)能够支持多种动态集 ...
- 学习javascript数据结构(四)——树
前言 总括: 本文讲解了数据结构中的[树]的概念,尽可能通俗易懂的解释树这种数据结构的概念,使用javascript实现了树,如有纰漏,欢迎批评指正. 原文博客地址:学习javascript数据结构( ...
- easyUI之Tree(树)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...
- Mysql存储引擎之TokuDB以及它的数据结构Fractal tree(分形树)
在目前的Mysql数据库中,使用最广泛的是innodb存储引擎.innodb确实是个很不错的存储引擎,就连高性能Mysql里都说了,如果不是有什么很特别的要求,innodb就是最好的选择.当然,这偏文 ...
随机推荐
- php中有关合并某一字段键值相同的数组合并
<?php function combine($array,$start,$key,$newkey){ static $new; //静态变量 foreach($array as $k=> ...
- 9.session的生命周期
1.创建 当客户端第一次访问某个jsp或者Servlet的时候,服务器会为当前会话创建一个SessionId,每次客户端向服务端发送请求的时候,都会将此SessionId携带过去,服务端会对此Sess ...
- 百万级数据mysql分区
1. 什么是表分区? 表分区,是指根据一定规则,将数据库中的一张表分解成多个更小的,容易管理的部分.从逻辑上看,只有一张表,但是底层却是由多个物理分区组成. 2. 表分区与分表的区别 分表:指的是通过 ...
- 本地服务器 windows server 2008 datacenter conn /as sysdba 提示 ora-01031 insufficient privileges
原因是需要把当前用户administrator(为例)添加到ora_dba组里. 服务器管理器--配置--本地用户和组--组
- 全网首创ISE入门级教程
转眼间我已经大三了,现在成为了实验室的负责人,对于下一届学生的纳新重任就交到了我的手上,想采取不同的方法暑假尽可能对他们进行一些培训,所以制作了此教程,说实话,在网上还没有找到关于ISE的入门级使用教 ...
- html中的锚点
一.页面内跳转的锚点设置 页面内的跳转需要两步: 方法一: ①:设置一个锚点链接<a href="#miao">去找喵星人</a>:(注意:href属性的属 ...
- CJOJ 1644 编辑距离 / Luogu 2758 编辑距离(动态规划)
CJOJ 1644 编辑距离 / Luogu 2758 编辑距离(动态规划) Description 字符串是数据结构和计算机语言里很重要的数据类型,在计算机语言中,对于字符串我们有很多的操作定义,因 ...
- Luogu 1111 修复公路(最小生成树)
Luogu 1111 修复公路(最小生成树) Description A地区在地震过后,连接所有村庄的公路都造成了损坏而无法通车.政府派人修复这些公路. 给出A地区的村庄数N,和公路数M,公路是双向的 ...
- RecyclerView线性分割线
由于recyclerview默认是没有分割线的,需要显示分割线的话,可以在布局里添加一条有背景色的View标签,或者通过ItemDecoration来实现,本文以后者为例. ItemDecoratio ...
- vue+webpack项目实际工作中需要生成一个配置文件供生产环境使用
大家都知道webpack打包十分方便,但是在工作中,前端写好的项目需要后端进行部署,就需要有一个配置文件. 使用插件 : GenerateAssetPlugin , 使用方法 : 1 在项目中安装 ...