# jstree
[jsTree](http://www.jstree.com/) is jquery plugin, that provides interactive trees. It is absolutely free, [open source](https://github.com/vakata/jstree) and distributed under the MIT license.
jsTree is easily extendable, themable and configurable, it supports HTML & JSON data sources, AJAX & async callback loading.
jsTree functions properly in either box-model (content-box or border-box), can be loaded as an AMD module, and has a built in mobile theme for responsive design, that can easily be customized. It uses jQuery's event system, so binding callbacks on various events in the tree is familiar and easy.
You also get:
* drag & drop support
* keyboard navigation
* inline edit, create and delete
* tri-state checkboxes
* fuzzy searching
* customizable node types
_Aside from this readme you can find a lot more info on [jstree.com](http://www.jstree.com) & [the discussion group](https://groups.google.com/forum/#!forum/jstree)_.
---
<!-- MarkdownTOC depth=0 autolink=true bracket=round -->
- [Getting Started](#getting-started)
- [Include all neccessary files](#include-all-neccessary-files)
- [Populating a tree using HTML](#populating-a-tree-using-html)
- [Populating a tree using an array (or JSON)](#populating-a-tree-using-an-array-or-json)
- [The required JSON format](#the-required-json-format)
- [Populating the tree using AJAX](#populating-the-tree-using-ajax)
- [Populating the tree using AJAX and lazy loading nodes](#populating-the-tree-using-ajax-and-lazy-loading-nodes)
- [Populating the tree using a callback function](#populating-the-tree-using-a-callback-function)
- [Working with events](#working-with-events)
- [Interacting with the tree using the API](#interacting-with-the-tree-using-the-api)
- [More on configuration](#more-on-configuration)
- [Plugins](#plugins)
- [checkbox](#checkbox)
- [contextmenu](#contextmenu)
- [dnd](#dnd)
- [massload](#massload)
- [search](#search)
- [sort](#sort)
- [state](#state)
- [types](#types)
- [unique](#unique)
- [wholerow](#wholerow)
- [More plugins](#more-plugins)
- [License & Contributing](#license--contributing)
<!-- /MarkdownTOC -->
---
## Getting Started
### Include all neccessary files
To get started you need 3 things in your page:
1. jQuery (anything above 1.9.1 will work)
2. A jstree theme (there is only one theme supplied by default)
3. The jstree source file
```html
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/jstree/3.0.9/themes/default/style.min.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/jstree/3.0.9/jstree.min.js"></script>
```
_If you decide to host jstree yourself - the files are located in the `dist` folder. You can safely ignore the `dist/libs` folder._
---
### Populating a tree using HTML
Now we are all set to create a tree, inline HTML is the easiest option (suitable for menus). All you need to do is select a node (using a jQuery selector) and invoke the `.jstree()` function to let jstree know you want to render a tree inside the selected node. `$.jstree.create(element)` can be used too.
```html
<div id="container">
<ul>
<li>Root node
<ul>
<li>Child node 1</li>
<li>Child node 2</li>
</ul>
</li>
</ul>
</div>
<script>
$(function() {
$('#container').jstree();
});
</script>
```
[view result](http://jsfiddle.net/vakata/2kwkh2uL/)
_You can add a few options when rendering a node using a data-attribute (note the quotes):_
```html
<li data-jstree='{ "selected" : true, "opened" : true }'>Root node ...
```
---
### Populating a tree using an array (or JSON)
Building trees from HTML is easy, but it is not very flexible, inline JS data is a better option:
```html
<div id="container"></div>
<script>
$(function() {
$('#container').jstree({
'core' : {
'data' : [
{ "text" : "Root node", "children" : [
{ "text" : "Child node 1" },
{ "text" : "Child node 2" }
]
}
]
}
});
});
</script>
```
[view result](http://jsfiddle.net/vakata/2kwkh2uL/1/)
Unlike the previous simple HTML example, this time the `.jstree()` function accepts a config object.
For now it is important to note that jstree will try to parse any data you specify in the `core.data` key and use it to create a tree. As seen in the previous example, if this key is missing jstree will try to parse the inline HTML of the container.
#### The required JSON format
The data you use must be in a specific format, each branch of the tree is represented by an object, which must at least have a `text` key. The `children` key can be used to add children to the branch, it should be an array of objects.
_Keep in mind, you can use a simple string instead of an object if all you need is node with the given text, the above data can be written as:_
```js
[ { "text" : "Root node", "children" : [ "Child node 1", "Child node 2" ] } ]
```
There are other available options for each node, only set them if you need them like:
* `id` - makes if possible to identify a node later (will also be used as a DOM ID of the `LI` node). _Make sure you do not repeat the same ID in a tree instance (that would defeat its purpose of being a unique identifier and may cause problems for jstree)_.
* `icon` - a string which will be used for the node's icon - this can either be a path to a file, or a className (or list of classNames), which you can style in your CSS (font icons also work).
* `data` - this can be anything you want - it is metadata you want attached to the node - you willbe able to access and modify it any time later - it has no effect on the visuals of the node.
* `state` - and object specifyng a few options about the node:
- `selected` - if the node should be initially selected
- `opened` - if the node should be initially opened
- `disabled` - if the node should be disabled
- `checked` - __checkbox plugin specific__ - if the node should be checked (only used when `tie_to_selection` is `false`, which you should only do if you really know what you are doing)
- `undetermined` - __checkbox plugin specific__ - if the node should be rendered in undetermined state (only used with lazy loading and when the node is not yet loaded, otherwise this state is automatically calculated).
* `type` - __types plugin specific__ - the type of the nodes (should be defined in the types config), if not set `"default"` is assumed.
* `li_attr` - object of values which will be used to add HTML attributes on the resulting `LI` DOM node.
* `a_attr` - object of values which will be used to add HTML attributes on the resulting `A` node.
Here is a new demo with some of those properties set:
```html
<div id="container"></div>
<script>
$(function() {
$('#container').jstree({
'core' : {
'data' : [
{
"text" : "Root node",
"state" : {"opened" : true },
"children" : [
{
"text" : "Child node 1",
"state" : { "selected" : true },
"icon" : "glyphicon glyphicon-flash"
},
{ "text" : "Child node 2", "state" : { "disabled" : true } }
]
}
]
}
});
});
</script>
```
[view result](http://jsfiddle.net/vakata/2kwkh2uL/11/)
---
### Populating the tree using AJAX
Building off of the previous example, let's see how to have jstree make AJAX requests for you.
```html
<div id="container"></div>
<script>
$(function() {
$('#container').jstree({
'core' : {
'data' : {
"url" : "//www.jstree.com/fiddle/",
"dataType" : "json" // needed only if you do not supply JSON headers
}
}
});
});
</script>
```
The server response is:
```json
[{
"id":1,"text":"Root node","children":[
{"id":2,"text":"Child node 1"},
{"id":3,"text":"Child node 2"}
]
}]
```
没有合适的资源?快使用搜索试试~ 我知道了~
jstree相关demo
共129个文件
js:34个
png:19个
css:14个
2星 需积分: 15 14 下载量 73 浏览量
2015-08-06
12:32:17
上传
评论
收藏 969KB ZIP 举报
温馨提示
jsTree是一个 基于jQuery的Tree控件。支持XML,JSON,Html三种数据源。提供创建,重命名,移动,删除,拖"放节点操作。可以自己自定义创建,删 除,嵌套,重命名,选择节点的规则。在这些操作上可以添加多种监听事件。
资源推荐
资源详情
资源评论
收起资源包目录
jstree相关demo (129个子文件)
asdf asdf 0B
asdfasdf 0B
asdfasdfasdfasdfasdf 0B
bootstrap.css 123KB
bootstrap.min.css 100KB
style.css 31KB
style.css 31KB
style.css 28KB
style.css 28KB
style.min.css 27KB
style.css 25KB
style.min.css 24KB
style.min.css 22KB
bootstrap-theme.css 19KB
bootstrap-theme.min.css 17KB
docs.css 5KB
qunit.css 5KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
glyphicons-halflings-regular.eot 20KB
throbber.gif 2KB
throbber.gif 2KB
throbber.gif 2KB
throbber.gif 2KB
throbber.gif 2KB
.gitignore 162B
.htaccess 13B
index.html 52KB
index.html 3KB
d.html 2KB
m.html 1KB
index.html 401B
ajax_nodes.html 64B
favicon.ico 1KB
jstree.js 260KB
jstree.js 200KB
jstree.js 146KB
jstree.min.js 119KB
jquery.js 94KB
jquery-1.10.2.min.js 91KB
jstree.min.js 90KB
qunit.js 62KB
bootstrap.js 57KB
jstree.checkbox.js 29KB
bootstrap.min.js 27KB
jstree.dnd.js 23KB
jstree.contextmenu.js 22KB
jquery.address-1.6.js 17KB
jstree.search.js 16KB
require.js 15KB
misc.js 11KB
jstree.types.js 9KB
gruntfile.js 7KB
docs.js 7KB
jquery.ui.touch.js 7KB
jstree.unique.js 5KB
jstree.wholerow.js 5KB
jstree.state.js 4KB
respond.js 4KB
html5.js 4KB
jstree.massload.js 3KB
vakata.js 3KB
sample.js 3KB
jstree.sort.js 2KB
vakata-jstree.js 1KB
intro.js 345B
test.js 315B
outro.js 4B
jstree.json 322KB
package.json 1KB
composer.json 1003B
component.json 542B
jstree.jquery.json 535B
bower.json 433B
ajax_demo_roots.json 149B
ajax_demo_children.json 139B
root.json 104B
ajax_roots.json 90B
ajax_children2.json 62B
ajax_children.json 62B
ajax_children2.json 62B
ajax_children.json 62B
base.less 5KB
mixins.less 5KB
main.less 4KB
responsive.less 4KB
style.less 2KB
style.less 645B
LICENSE-MIT 1KB
README.md 23KB
共 129 条
- 1
- 2
资源评论
- number__2018-10-09不好用 垃圾
1060351485
- 粉丝: 1
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功