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. 【剑指offer】09-3变态跳台阶

    原创博文,转载请注明出处! # 本文是牛客网<剑指offer>刷题笔记,笔记索引连接 1.题目 # 一只青蛙一次可以跳上1级台阶,也可以跳上2级……它也可以跳上n级.求该青蛙跳上一个n级的 ...

  2. Cocos2d-X 3.2环境的配置

    大三寒假时间特别长,终于准备坐下来好好去学一直想涉足的游戏开发.既然准备学,就要找个出色的.跨平台的引擎来实现自己的计划.最终我选定了Cocos2d-X. 在折腾了很久之后,我终于把Cocos2d-X ...

  3. Unity的 NavMeshObstacle 的使用详解

            这个组件放在场景中的导航网格上,可以阻挡NavMeshAgent的移动.以Unity4.3.4为例.         NavMeshObstacle 分为两种模式,一种是普通模式,通过 ...

  4. HDU - 1142:A Walk Through the Forest (拓扑排序)

    Jimmy experiences a lot of stress at work these days, especially since his accident made working dif ...

  5. HihoCoder1050 树中的最长路 树形DP第三题(找不到对象)

    题意:求出的树中距离最远的两个结点之间相隔的距离. 水题一道,以前只会用路的直径来解. 代码如下: #include<cstdio> #include<cstdlib> #in ...

  6. 让控制台支持 ANSI 转义序列,输出下划线、修改颜色或其他控制

    各种操作系统的控制台都支持 ANSI 转义序列(ANSI Escape Code).使用转义序列,可以对控制台进行很多额外的定制,例如修改颜色.修改标题栏,将文字添加下划线等. 当然,.NET 已经帮 ...

  7. mysql 关联左表不存在数据 并 根据身份证计算查找大于65岁以上老人

    --- //查找左边不存在数据,不能用 = '' SELECT m.uid FROM es_members m LEFT JOIN es_user_self_care_assessment u ON ...

  8. php基础语法(数据类型、运算符)

    数据类型 标量类型: int, float, string, bool 复合类型: array, object 特殊类型: null, resouce 整数类型int, integer 字符串类型st ...

  9. tomcat深入学习

    总体结构:https://www.jianshu.com/p/d74eef07487f servlet相关:https://www.ibm.com/developerworks/cn/java/j-l ...

  10. linux的mysql

    mysql https://www.cnblogs.com/cnblogsfans/archive/2009/09/21/1570942.html https://blog.csdn.net/Smal ...