# 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)
- [PHP demos moved to new repository](#php-demos-moved-to-new-repository)
- [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/3.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/jstree/3.3.3/themes/default/style.min.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/jstree/3.3.3/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/4478/)
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 will be able to access and modify it any time later - it has no effect on the visuals of the node.
* `state` - an 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_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/4479/)
---
### 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":[
{"
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
小诗科技2.0开源平台单工程工作流版本, 采用技术为: spring,springBoot,Mybatis,Mysql,Redis,Activiti,自研BPM可视化设计器兼容IE,火狐,谷歌,360等浏览器,集成系统性能监控模块,tk压缩,VUE,数据库读写分离,MQ消息中间件等技术
资源推荐
资源详情
资源评论
收起资源包目录
JEHC-CLOUD基于Spring Cloud 2.X版本,采用前后端分离,集成了多方向平台如互联网物联网传统软件医疗医疗方向 (2000个子文件)
style.bundle.css 1.4MB
vendors.bundle.css 349KB
icons.css 173KB
bootstrap.css 148KB
bootstrap.min.css 141KB
index.css 140KB
bootstrap.min.css 115KB
style.css 113KB
materialdesignicons.css 107KB
materialdesignicons.css 107KB
materialdesignicons.min.css 85KB
materialdesignicons.css 83KB
u-table.css 71KB
bootstrap-icons.css 64KB
ux-grid.css 63KB
all.css 57KB
bootstrap-icons.min.css 56KB
bootstrap-icons.min.css 56KB
fontawesome.css 56KB
viewer.css 52KB
all.min.css 46KB
fontawesome.min.css 44KB
v4-shims.css 40KB
font-awesome.css 36KB
font-awesome.css 36KB
skin.min.css 34KB
style.css 34KB
style.css 34KB
skin.ie7.min.css 32KB
line-awesome.css 32KB
line-awesome.css 32KB
line-awesome-font-awesome.css 32KB
line-awesome-font-awesome.css 32KB
font-awesome.css 32KB
style.css 31KB
style.css 31KB
font-awesome.min.css 30KB
jquery-ui.min.css 29KB
style.min.css 29KB
bootstrap-datepicker3.standalone.css 29KB
bootstrap-datepicker3.css 28KB
line-awesome.min.css 27KB
line-awesome.min.css 27KB
line-awesome-font-awesome.min.css 27KB
line-awesome-font-awesome.min.css 27KB
style.min.css 26KB
bootstrap-datepicker3.standalone.min.css 26KB
font-awesome.min.css 26KB
v4-shims.min.css 26KB
bootstrap-datepicker3.min.css 26KB
typicons.css 24KB
spinkit.css 23KB
custombox.min.css 23KB
datatables.bundle.rtl.css 22KB
datatables.bundle.css 21KB
bootstrap-editable.css 21KB
sweetalert2.css 19KB
bootstrap-datepicker.standalone.css 18KB
select2.css 17KB
bootstrap-datepicker.css 17KB
tablesaw.css 16KB
bootstrap-datepicker.standalone.min.css 15KB
bootstrap-datepicker.min.css 15KB
summernote-bs4.css 15KB
common.css 15KB
select2.min.css 15KB
bootstrap-datepicker.min.css 15KB
sweetalert2.min.css 14KB
style-light.css 14KB
fullcalendar.min.css 13KB
formValidation.css 13KB
formValidation.rtl.css 13KB
flaticon.css 12KB
simple-line-icons.css 12KB
simple-line-icons.css 12KB
dropzone.css 12KB
flaticon.css 12KB
bootstrap-datetimepicker.css 12KB
flaticon.css 12KB
dripicons.css 11KB
dripicons.css 11KB
simple-line-icons.css 11KB
bootstrap-datetimepicker.min.css 11KB
rwd-table.min.css 11KB
chartist.min.css 11KB
pe-icon-7-stroke.css 10KB
formValidation.min.rtl.css 9KB
formValidation.min.css 9KB
simple-line-icons.min.css 9KB
socicon.css 9KB
flaticon.css 9KB
daterangepicker.css 8KB
magnific-popup.css 8KB
bootstrap-select.css 8KB
svg-with-js.css 7KB
style.css 7KB
shCoreDefault.css 7KB
toastr.css 7KB
feather.css 7KB
feather.css 7KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 6713
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功