ztree--插件实现增删改查demo(完整版)

var setting = {
                async: {
                    enable: true,       //开启异步加载处理
                    dataFilter: filter  //用于对 Ajax 返回数据进行预处理的函数
                },
                view: {
                    addHoverDom: addHoverDom,
                    removeHoverDom: removeHoverDom,
                    selectedMulti: false,
                },
                check: {
                    enable: false
                },
                data: {
                    simpleData: {
                        enable: true
                    }
                },
                edit: {
                    enable: true,
                    removeTitle: "删除",
                    renameTitle: "编辑名称"
                },
                callback: {
                    //用于捕获节点被删除之前的事件回调函数,并且根据返回值确定是否允许删除操作
                    beforeRemove: beforeRemove,
                    //用于捕获节点编辑名称结束(Input 失去焦点 或 按下 Enter 键)之后,
                    //更新节点名称数据之前的事件回调函数,并且根据返回值确定是否允许更改名称的操作
                    beforeRename: beforeRename,
                    //用于捕获节点被点击的事件回调函数
                    onClick: zTreeOnClick
                }
            };
            var zNodes = date;
            $.fn.zTree.init($("#treeDemo"), setting, zNodes);
            $('.ico_open').remove();
            $('.ico_docu').remove();
            //添加新的节点
            function addHoverDom(treeId, treeNode) {
                if (treeNode.level === 2) {
                    return false;
                } else {
                    var sObj = $("#" + treeNode.tId + "_span");
                    if (treeNode.editNameFlag || $("#addBtn_" + treeNode.tId).length > 0) return;
                    if (treeNode.level === 0) {
                        var addStr = "<span class='button add' id='addBtn_" + treeNode.tId
                            + "' title='添加部门' onfocus='this.blur();'></span>";
                        sObj.after(addStr);
                    }
                    if (treeNode.level === 1) {
                        var addStr = "<span class='button add' id='addBtn_" + treeNode.tId
                            + "' title='添加班组' onfocus='this.blur();'></span>";
                        sObj.after(addStr);
                    }
                    var btn = $("#addBtn_" + treeNode.tId);
                    if (btn) btn.bind("click", function () {
                        if (treeNode.name) {
                            var parentId = treeNode.id;
                            var orgName = treeNode.name;
                            $.ajax({
                                url: baseUrl + 'system/department/add',
                                type: "post",
                                data: {
                                    orgName: orgName,
                                    parentId: parentId
                                },
                                success: function (res) {
                                    if (res.status == "0000") {
                                        toastr.success('添加成功!')
                                        me.ztree()
                                    } else {
                                        toastr.error('添加失败!')
                                    }
                                }
                            });
                        }
                    });
                }
            };
            function removeHoverDom(treeId, treeNode) {
                $("#addBtn_" + treeNode.tId).unbind().remove();
            };
            //删除节点信息
            function beforeRemove(treeId, treeNode) {
                var zTree = $.fn.zTree.getZTreeObj("treeDemo");
                zTree.selectNode(treeNode);
                if (treeNode.name) {
                    var sids = [];
                    sids.push(treeNode.id)
                    $.ajax({
                        url: baseUrl + 'system/department/delete',
                        type: "post",
                        data: {
                            sids: sids
                        },
                        success: function (res) {
                            if (res.status == "0000") {
                                toastr.success('删除成功')
                            } else {
                                toastr.error(res.message)
                                me.ztree()
                            }
                        }
                    });
                } else {
                    window.location.reload();
                }
            }
            //修改节点信息
            function beforeRename(treeId, treeNode, newName) {
                if (newName.length == 0) {
                    toastr.error('节点名称不能为空')
                    return false;
                } else if (newName.length >= 15) {
                    toastr.error('节点名称长度不得超出14个字符')
                    return false;
                } else if (/^\s+$/gi.test(newName)) {
                    toastr.error('节点名称不能以空格')
                    return false;
                }
                var pNode = treeNode.getParentNode();
                var parentId;
                var sid = treeNode.id;
                if (pNode == null) {
                    parentId = 0;
                } else {
                    parentId = pNode.id;
                }
                $.ajax({
                    url: baseUrl + 'system/department/edit',
                    type: "post",
                    data: {
                        sid: sid,
                        orgName: newName,
                        parentId: parentId
                    },
                    success: function (res) {
                        if (res.status == "0000") {
                            toastr.success('修改成功!')
                        } else {
                            toastr.error('修改失败!')
                        }
                    }
                });
            }
            //修改异步获取到的节点name属性
            function filter(treeId, parentNode, childNodes) {
                if (!childNodes) return null;
                for (var i = 0, l = childNodes.length; i < l; i++) {
                    childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');
                }
                return childNodes;
            }
            //点击节点后, 弹出该节点的 tId、name 的信息
            function zTreeOnClick(event, treeId, treeNode) {
                if (treeNode.pId === null || treeNode.pId==0) {
                    $('#table').bootstrapTable('refresh', {
                        url: baseUrl + 'system/person/list?organizationId=' + ""
                    })
                } else {
                    $('#table').bootstrapTable('refresh', {
                        url: baseUrl + 'system/person/list?organizationId=' + treeNode.id
                    })
                }
            };

ztree--插件实现增删改查demo(完整版)的更多相关文章

  1. ssm学习(四)--完整的增删改查demo

    上一篇文章简要介绍了将sping mvc加入整个框架,算是完成了ssm的集成.本节继续前面的内容,结合spring mvc做一个简单的增删改查demo. 1.首先,重写一下GeckoList.jsp页 ...

  2. 【讲义提纲】以一个实战新闻cms增删改查demo为例,给学院国创队伍培训php

    PHP实战基础——以一个新闻cms的增删改查为例 一.        环境配置 二.        数据库创建 三.        增删改查demo 连接数据库 <?php $link=mysq ...

  3. mvc模式jsp+servel+dbutils oracle基本增删改查demo

    mvc模式jsp+servel+dbutils oracle基本增删改查demo 下载地址

  4. mvc模式jsp+servel+jdbc oracle基本增删改查demo

    mvc模式jsp+servel+jdbc oracle基本增删改查demo 下载地址

  5. SSH登录与增删改查demo详解+源代码

    点击下载,测试绝对可用SSH整合框架登录加增删改查demo 下载地址:http://download.csdn.net/detail/qq_33599520/9784679   一.框架概述 spri ...

  6. hibernate之增删改查demo

    package dao; import java.util.ArrayList; import java.util.List; import org.hibernate.Query; import o ...

  7. asp.net数据库增删改查demo

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  8. spring boot + jpa + bootstrap + thymeleaf 简单的增删改查Demo

    对springboot和bootstrap初学者来说是一个不错Demo 下载地址:点击进入下载Demo 首页(http://localhost:8081) 增加 编辑 搜索

  9. Vue 增删改查 demo

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

随机推荐

  1. android 获取 图片或视频略缩图

    /** * 根据指定的图像路径和大小来获取缩略图 此方法有两点好处: 1. * 使用较小的内存空间,第一次获取的bitmap实际上为null,只是为了读取宽度和高度, * 第二次读取的bitmap是根 ...

  2. 使用Postman对Restful接口进行测试

    趁着项目需要,花了两天时间对postman进行了一下学习,因为看到各大测试群,各个初入测试的孩子们都在问postman,但其实网上也有很多的教程,这里我就再来发一篇. 1. Http协议 要对接口进行 ...

  3. HDU - 4339: Query(bitset暴力找下一个为1的)

    题意:给定A,B长度相同的字符串,Q次操作,修改操作位单个字符修改,查询操作为询问从某点开始有多少连续相同的字符. 思路:我们把不相同的设为1,相同的设为0,那么询问就是找下一个为1的为位置,可以用线 ...

  4. HihoCoder 1055 : 刷油漆 树形DP第一题(对象 点)

    刷油漆 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 上回说到,小Ho有着一棵灰常好玩的树玩具!这棵树玩具是由N个小球和N-1根木棍拼凑而成,这N个小球都被小Ho标上了 ...

  5. 自定义vue全局组件use使用(解释vue.use()的原理)

    我们在前面学习到是用别人的组件:Vue.use(VueRouter).Vue.use(Mint)等等.其实使用的这些都是全剧组件,这里我们就来讲解一下怎么样定义一个全局组件,并解释vue.use()的 ...

  6. jest js 测试框架-简单方便人性化

    1. 安装 yarn global add jest-cli or npm install -g jest-cli 备注:可以安装为依赖不用全局安装 2. 项目代码 a. 项目初始化 yarn ini ...

  7. win10下启动zkui

    zkui是一个开源的zookeeper可视化工具,现在看下我们怎么启动这个工具.首先下载源码(我把它放在E:\workspace): git clone https://github.com/Deem ...

  8. EF6:编写你自己的code first 数据迁移操作(睡前来一篇,翻译的)

    原英文版由EF团队成员 Rowan Miller 在2013年发表,此处只作翻译备忘. 数据迁移提供了一套强类型API,用于执行通用的操作,比如CreateIndex("dbo.Blogs& ...

  9. O/R映射及OID方案

    一.O/R映射层基本介绍 O/R映射层是持久层的一个特例,它的数据模型是对象模型(Object),存储模型是关系模型(Relational),cmp和Hibernate是对象模型到关系模型之间转换的两 ...

  10. php 常用方法

    //返回json数据给js function json_output($err_code = 0 , $error_message = '' , $data = [] , $redirect = '' ...