官网地址:https://www.jstree.com/

json返回参数格式:推荐第二种方式 不需要在重新拼接返回格式

不刷新页面重新初始化 jstree时使用:$.jstree.destroy()  注销已初始化的数据

虚线设置:在 plugins中添加wholerow。如: plugins: ["wholerow","contextmenu"]   contextmenu是快捷菜单配置

1、拼接子节点格式

// Expected format of the node (there are no required fields)
{
id : "string" // will be autogenerated if omitted
text : "string" // node text
icon : "string" // string for custom
state : {
opened : boolean // is the node open
disabled : boolean // is the node disabled
selected : boolean // is the node selected
},
children : [] // array of strings or objects
li_attr : {} // attributes for the generated LI node
a_attr : {} // attributes for the generated A node
}

2、根据父节点组装,注:parent是父级节点,初始节点为 " # "

// Alternative format of the node (id & parent are required)
{
id : "string" // required
parent : "string" // required
text : "string" // node text
icon : "string" // string for custom
state : {
opened : boolean // is the node open
disabled : boolean // is the node disabled
selected : boolean // is the node selected
},
li_attr : {} // attributes for the generated LI node
a_attr : {} // attributes for the generated A node
}

html

  <div id="treeDiv" > </div>

初始化js

$('#treeDiv').jstree({
'core': {
'data': data//返回的数据
},
});

添加右键点击自定义菜单

            $('#treeDiv').jstree({
'core': {
'data': data
},
plugins: ["contextmenu"],
"contextmenu": {
"items": {
"create": null,
"rename": null,
"remove": null,
"ccp": null,
"add": {
"label": "add",
"action": function (obj) {
alert("add operation--clickedNode's id is:" + obj);
}
},
"delete": {
"label": "delete",
"action": function (obj) {
alert("add operation--clickedNode's id is:" + obj);
}
}
}
}
});

虚线设置:在 plugins中添加wholerow。如: plugins: ["wholerow","contextmenu"]   contextmenu是快捷菜单配置

拖动效果

$("#treeDiv").jstree({
"core": {
"check_callback": true,
"data":data
},
"plugins": ["dnd"]
});

拖动返回事件

 $("#treeDiv").on('move_node.jstree', function (e, data) {
$.post("modulemng/dndmodule", {
id: data.node.id,
parent: data.parent,
position: data.position
}, function (data, status) {
alert("Data: " + data + "\nStatus: " + status);
});
});

初始化完成后展开所有节点

$("#treeDiv").on("ready.jstree", function (e, data) {   //树创建完成事件
data.instance.open_all(); //展开所有节点
});

获取当前选择的节点

 $("#treeDiv").on('changed.jstree', function (e, data) {   //选中节点改变事件
var node = data.instance.get_node(data.selected[0]); //获取选中的节点
});

【笔记】jstree插件的基本使用的更多相关文章

  1. 利用jstree插件轻松构建树应用

    最近完成了项目中的一个树状应用,第一次接触了jstree这个插件,总的来说它的官方文档还是比较详细的,但是在使用过程中还是出现了一些问题,下面我就来谈谈这款插件的使用和心得. 首先项目需要构建一棵树, ...

  2. 为知笔记markdown插件安装

    Wiz.Editor.md 是一个基于 Editor.md 构建的为知笔记 Markdown 插件. 主要特性 多种样式主题 支持实时预览 支持代码高亮 支持搜索替换 支持ToC目录 Tex数学公式 ...

  3. amazeui学习笔记--js插件(UI增强)--警告框Alert

    amazeui学习笔记--js插件(UI增强)--警告框Alert 一.总结 1.警告框基本样式:用am-alert声明div容器, <div class="am-alert" ...

  4. amazeui学习笔记--js插件(UI增强4)--下拉组件Dropdown

    amazeui学习笔记--js插件(UI增强4)--下拉组件Dropdown 一.总结 1.am-dropdown(及其孩子):控制下拉列表的样式 2.data-am-dropdown(及其孩子):控 ...

  5. amazeui学习笔记--js插件(UI增强3)--折叠面板Collapse

    amazeui学习笔记--js插件(UI增强3)--折叠面板Collapse 一.总结 注意点: 1.data-am-collapse:这个东西就是展开折叠事件 2.am-collapse(包括其下属 ...

  6. amazeui学习笔记--js插件(UI增强2)--按钮交互Button

    amazeui学习笔记--js插件(UI增强2)--按钮交互Button 一.总结 1.按钮loading状态: <button type="button" class=&q ...

  7. jstree 插件的使用笔记(一)

    官方:http://www.jstree.com/  一.节点的描述 官方资料:http://www.jstree.com/docs/json/ 格式一 { id : "string&quo ...

  8. elasticsearch学习笔记——相关插件和使用场景

    logstash-input-jdbc学习 ES(elasticsearch缩写)的一大优点就是开源,插件众多.所以扩展起来非常的方便,这也造成了它的生态系统越来越强大.这种开源分享的思想真是与天朝格 ...

  9. jsTree插件简介(三)

    UI-plugin JSTree的UI插件:用来处理选择.不选和鼠标悬浮树选项的插件. 一.属性包括: 1.select_limit:指定一次可以选中几个节点,默认为-1,表示无限制选中. 2.sel ...

随机推荐

  1. 『.NET Core CLI工具文档』(九)dotnet-run

    说明:本文是个人翻译文章,由于个人水平有限,有不对的地方请大家帮忙更正. 原文:dotnet-run 翻译:dotnet-run 名称 dotnet-run -- 没有任何明确的编译或启动命令运行&q ...

  2. WPF入门:XAML

    XAML是WPF技术中专门用于设计UI的语言 XAML优点最大的优点是将UI与逻辑代码剥离 创建第一个WPF应用程序 VS默认生成的WPF项目解决方案 Properties:里面主要包含了程序用到的一 ...

  3. 和Java相关的书籍,想成为架构师的请收藏一下啊

    1.<<Effective Java 中文第二版>> 2.<<Java并发编程实践>> 3.<<Java核心技术(原书第8版)卷I_基础知识 ...

  4. jquery获取dropdownlist的value和text值

    1.jquery //获取value值 $("#ddlSubmodel").val(); //获取text值 $("#ddlSubmodel").find(&q ...

  5. POJ-3032

    算法 准备一个最多能存放13个元素的队列,开始时队列为空. 1. 输入n. 3. 将n加入队列. 4. 令i从n到2执行: // 此时队列中有n-i+1个元素 将i-1加入到队列首部. // 此时队列 ...

  6. 你知道JavaScript中的结果值是什么吗?

    你知道JavaScript中的每条语句.甚至表达式都有一个结果值吗? 当你在浏览器中测试代码时,经常会在控制台的输出结果的最后面多出一条,大部分为undefined,这个undefined就是一个结果 ...

  7. JavaScript中的slice,splice,substr,substring,split的区别

    万恶的输入法,在sublime中会显示出繁体字,各位看官见谅. 1.slice()方法:该方法在数组和string对象中都拥有. var a = [1,2,3,4,5,6]; var s = 'thi ...

  8. Android 手机卫士--绑定sim卡序列号

    现在开始具体 处理每一个导航页面的逻辑,首先看第二个导航页 本文地址:http://www.cnblogs.com/wuyudong/p/5949775.html,转载请注明出处. 这里需要实现绑定s ...

  9. ios动态创建类Class

    [Objective-C Runtime动态加载]---动态创建类Class 动态创建类Class,动态添加Class成员变量与成员函数,动态变量赋值与取值,动态函数调用等方法 a.使用objc_al ...

  10. ASP.NET MVC的客户端验证:jQuery验证在Model验证中的实现

    在简单了解了Unobtrusive JavaScript形式的验证在jQuery中的编程方式之后,我们来介绍ASP.NET MVC是如何利用它实现客户端验证的.服务端验证最终实现在相应的ModelVa ...