jsTree使用记录
1. ajax请求生成jsTree
- <span style="font-size:14px;"><script>
- var r = []; // 权限树中被选中的叶子节点
- var currentGroupId;
- function showPermitTree(id) {
- currentGroupId = id;
- $.ajax({
- data : "currentGroupId=" + id,
- type : "POST",
- //dataType : 'json',
- url : "/test/permittree",
- error : function(data) {
- alert("出错了!!:" + data);
- },
- success : function(data) {
- //alert("success:" + data);
- createPermitTree(data);
- }
- });
- ${'buttonDiv'}.style.display="";
- }
- function createPermitTree(datastr) {
- datastr = eval("" + datastr + "");
- $('#permitTree').jstree({
- 'plugins' : [ "wholerow", "checkbox", "types" ],
- 'core' : {
- "themes" : {
- "responsive" : false
- },
- 'data' : datastr
- },
- "types" : {
- "default" : {
- "icon" : "fa fa-folder icon-state-warning icon-lg"
- },
- "file" : {
- "icon" : "fa fa-file icon-state-warning icon-lg"
- }
- }
- });
- }
- // listen for event
- $('#permitTree').on('changed.jstree', function(e, data) {
- r = [];
- var i, j;
- for (i = 0, j = data.selected.length; i < j; i++) {
- var node = data.instance.get_node(data.selected[i]);
- if (data.instance.is_leaf(node)) {
- r.push(node.id);
- }
- }
- //alert('Selected: ' + r.join('@@'));
- })
- function saveTree() {
- $.ajax({
- data : {'currentGroupId' : currentGroupId,
- 'selectedNodes' : r.join('@@')},
- type : "POST",
- //dataType : 'json',
- url : "/test/savetree",
- error : function(data) {
- alert("出错了!!:" + data);
- },
- success : function(data) {
- alert("保存成功!");
- }
- });
- }
- </script></span><span style="font-size:24px;">
- </span>
直接把测试项目中一段代码copy过来了,这是一棵带复选框的树。页面有地方点击之后触发showPermitTree(id)函数,发送ajax请求给后台,项目使用的是springmvc框架,后台返回JSONArray.toString。
2. jsTree change事件
上面代码中含change事件。把所有选中的节点的id放到一个数组中。
页面上有个按钮,点击后触发saveTree函数,发请求给后台,把选中的节点的id发给后台。
3.jsTree自定义contextmenu
- <script>
- $('#jstree').jstree({
- core : {
- check_callback : true,
- data : [
- { "id" : "1", "parent" : "#", "text" : "root" },
- { "id" : "2", "parent" : "1", "text" : "child 1" },
- { "id" : "3", "parent" : "1", "text" : "child 2" }
- ],
- },
- plugins : ["wholerow","contextmenu"],
- "contextmenu": {
- "items": {
- "create": null,
- "rename": null,
- "remove": null,
- "ccp": null,
- "add": {
- "label": "add",
- "action": function (obj) {
- var inst = jQuery.jstree.reference(obj.reference);
- var clickedNode = inst.get_node(obj.reference);
- alert("add operation--clickedNode's id is:" + clickedNode.id);
- }
- },
- "delete": {
- "label": "delete",
- "action": function (obj) {
- var inst = jQuery.jstree.reference(obj.reference);
- var clickedNode = inst.get_node(obj.reference);
- alert("delete operation--clickedNode's id is:" + clickedNode.id);
- }
- }
- }
- }
- }).on("ready.jstree", function (e, data) {
- data.instance.open_all();
- });
- </script>
这段代码使用jsTree的contextmenu plugin,去掉jsTree自带的菜单,并自定义菜单
- 顶
- 8
- 踩
jsTree使用记录的更多相关文章
- jstree的基本应用----记录
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- 基于Metronic的Bootstrap开发框架经验总结(2)--列表分页处理和插件JSTree的使用
在上篇<基于Metronic的Bootstrap开发框架经验总结(1)-框架总览及菜单模块的处理>介绍了Bootstrap开发框架的一些基础性概括,包括总体界面效果,以及布局.菜单等内容, ...
- 使用插件bootstrap-table实现表格记录的查询、分页、排序等处理
在业务系统开发中,对表格记录的查询.分页.排序等处理是非常常见的,在Web开发中,可以采用很多功能强大的插件来满足要求,且能极大的提高开发效率,本随笔介绍这个bootstrap-table是一款非常有 ...
- 在Bootstrap开发框架中使用bootstrapTable表格插件和jstree树形列表插件时候,对树列表条件和查询条件的处理
在我Boostrap框架中,很多地方需要使用bootstrapTable表格插件和jstree树形列表插件来共同构建一个比较常见的查询界面,bootstrapTable表格插件主要用来实现数据的分页和 ...
- 基于Metronic的Bootstrap开发框架经验总结(16)-- 使用插件bootstrap-table实现表格记录的查询、分页、排序等处理
在业务系统开发中,对表格记录的查询.分页.排序等处理是非常常见的,在Web开发中,可以采用很多功能强大的插件来满足要求,且能极大的提高开发效率,本随笔介绍这个bootstrap-table是一款非常有 ...
- (转)基于Metronic的Bootstrap开发框架经验总结(2)--列表分页处理和插件JSTree的使用
http://www.cnblogs.com/wuhuacong/p/4759564.html 在上篇<基于Metronic的Bootstrap开发框架经验总结(1)-框架总览及菜单模块的处理& ...
- 树组件——jstree使用
本文记录的只是我自己当时的代码,每行的注释很清楚了,你自己可以做相应变通 一.使用前提: 1.下载jstree依赖包 2.相关页面引入样式["jstree/themes/default/st ...
- 前端-jstree 一些常用功能
最近使用到了jstree(v3.3.4)这个插件(官网:https://www.jstree.com/),在这里记录下我的使用过程的一些技巧和问题. 1. 获取数据 一般实际项目中用到的数据都是aja ...
- 记一次debug记录:Uncaught SyntaxError: Unexpected token ILLEGAL
在使用FIS3搭建项目的时候,遇到了一些问题,这里记录下. 这里是发布搭建代码: // 代码发布时 fis.media('qa') .match('*.{js,css,png}', { useHash ...
随机推荐
- MySQL常用函数(转)
一.数学函数 ABS(x):返回x的绝对值 BIN(x):返回x的二进制(OCT返回八进制,HEX返回十六进制) CEILING(x):返回大于x的最小整数值 EXP(x):返回值e(自然对数的底)的 ...
- one troubleshooting case about em access issue
Today when trying to open my Oracle EM url, I can not open it. So I thought may be the network is ha ...
- 用JQuery实现选中select里面的option显示对应的div
HTML: <select name="" onchange="select(this)"> <option value="1&q ...
- HDU1813:Escape from Tetris(IDA)
Problem Description 因为整日整夜地对着这个棋盘,Lele最终走火入魔.每天一睡觉.他就会梦到自己会被人被扔进一个棋盘中,一直找不到出路,然后从梦中惊醒.久而久之,Lele被搞得精神 ...
- LeetCode 172. Factorial Trailing Zeroes (阶乘末尾零的数量)
Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in log ...
- [Unity 设计模式]IOC依赖倒置
1.前言 最近在看<游戏开发与设计模式>一书,看到控制反转设计模式,作者说:上层模块不应该依赖于下层模块,上层模块和下层模块都应该依赖于接口,这样能减少耦合.然后附带举了个例子,我觉得特别 ...
- luogu 1045 麦森数
题目大意: 从文件中输入P(1000<P<3100000),计算2^P−1的位数和最后500位数字(用十进制高精度数表示) 思路: 一道高精度练习题 其中位数是一个结论 位数=[P*log ...
- [Codeplus 2017] 晨跑
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=5105 [算法] 答案为三个数的最小公倍数 [代码] #include<bits ...
- poi导出excel改变标题颜色
在excelutil类里面添加 public class ExcelUtil { public static Workbook fillExcelData(ResultSet rs, Workbook ...
- idea ssm项目移包报错问题
写完代码之后发现包结构太乱了 想要规划一下 结果报错 这里面的包路径都可以点进去,还是报找不到com.lf.company.entity.Business 后来发现是 在移动前和移动后都存在这个m ...