页面

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ZTree3.aspx.cs" Inherits="WebTest.ZTree3" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="zTree_v3/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" />
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="zTree_v3/js/jquery.ztree.core-3.5.min.js" type="text/javascript"></script>
<script src="zTree_v3/js/jquery.ztree.excheck-3.5.min.js" type="text/javascript"></script>
<script src="zTree_v3/js/jquery.ztree.exedit-3.5.min.js" type="text/javascript"></script>
<script type="text/javascript">
var setting = {
view: {
addHoverDom: addHoverDom,
removeHoverDom: removeHoverDom,
selectedMulti: false
},
edit: {
enable: true,
editNameSelectAll: true,
showRemoveBtn: showRemoveBtn,
showRenameBtn: showRenameBtn,
showRenameBtn: isLastNode = true, //最后一个节点是否显示编辑按钮
showRenameBtn: isFirstNode = true, //第一个节点是否显示编辑按钮
showRemoveBtn: isFirstNode = true//第一个节点显示移除
},
data: {
simpleData: {
enable: true
}
},
callback: {
//beforeDrag: beforeDrag,
//beforeEditName: beforeEditName,
beforeRemove: beforeRemove,
beforeRename: beforeRename,
onRemove: onRemove,
onRename: onRename,
onDrop: zTreeOnDrop
}
};

// var zNodes = [
// { id: 1, pId: 0, name: "父节点 1", open: true },
// { id: 11, pId: 1, name: "叶子节点 1-1" },
// { id: 12, pId: 1, name: "叶子节点 1-2" },
// { id: 13, pId: 1, name: "叶子节点 1-3" },
// { id: 2, pId: 0, name: "父节点 2", open: true },
// { id: 21, pId: 2, name: "叶子节点 2-1" },
// { id: 22, pId: 2, name: "叶子节点 2-2" },
// { id: 23, pId: 2, name: "叶子节点 2-3" },
// { id: 3, pId: 0, name: "父节点 3", open: true },
// { id: 31, pId: 3, name: "叶子节点 3-1" },
// { id: 32, pId: 3, name: "叶子节点 3-2" },
// { id: 33, pId: 3, name: "叶子节点 3-3" }
// ];
var log, className = "dark";
function zTreeOnDrop(event, treeId, treeNodes, targetNode, moveType) {
Exec(3, treeNodes[0].id, 0, targetNode.id); //修改上级
// alert(targetNode.id);
// alert(treeNodes.length + "," + (targetNode ? (targetNode.tId + ", " + targetNode.name) : "isRoot"));
};
function zTreeOnDrag(event, treeId, treeNodes) {
alert(treeNodes.length);
};
function beforeEditName(treeId, treeNode) {
className = (className === "dark" ? "" : "dark");
showLog("[ " + getTime() + " beforeEditName ]&nbsp;&nbsp;&nbsp;&nbsp; " + treeNode.name);
var zTree = $.fn.zTree.getZTreeObj("treeDemo");
zTree.selectNode(treeNode);
return confirm("进入节点 -- " + treeNode.name + " 的编辑状态吗?");
}
function beforeRemove(treeId, treeNode) {
className = (className === "dark" ? "" : "dark");
showLog("[ " + getTime() + " beforeRemove ]&nbsp;&nbsp;&nbsp;&nbsp; " + treeNode.name);
var zTree = $.fn.zTree.getZTreeObj("treeDemo");
zTree.selectNode(treeNode);
return confirm("确认删除 节点 -- " + treeNode.name + " 吗?");
}
function onRemove(e, treeId, treeNode) {
Exec(4, treeNode.id, 0, 0); //修改上级
//showLog("[ " + getTime() + " onRemove ]&nbsp;&nbsp;&nbsp;&nbsp; " + treeNode.name);
}
function beforeRename(treeId, treeNode, newName, isCancel) {
className = (className === "dark" ? "" : "dark");
showLog((isCancel ? "<span style='color:red'>" : "") + "[ " + getTime() + " beforeRename ]&nbsp;&nbsp;&nbsp;&nbsp; " + treeNode.name + (isCancel ? "</span>" : ""));
if (newName.length == 0) {
alert("节点名称不能为空.");
var zTree = $.fn.zTree.getZTreeObj("treeDemo");
setTimeout(function () { zTree.editName(treeNode) }, 10);
return false;
}
return true;
}
function onRename(e, treeId, treeNode, isCancel) {
Exec(2, treeNode.id, treeNode.name,0); //修改
// alert(treeNode.id + "|" + treeNode.name);
// showLog((isCancel ? "<span style='color:red'>" : "") + "[ " + getTime() + " onRename ]&nbsp;&nbsp;&nbsp;&nbsp; " + treeNode.name + (isCancel ? "</span>" : ""));
}
function showRemoveBtn(treeId, treeNode) {
return !treeNode.isFirstNode;
}
function showRenameBtn(treeId, treeNode) {
return !treeNode.isLastNode;
}
function showLog(str) {
if (!log) log = $("#log");
log.append("<li class='" + className + "'>" + str + "</li>");
if (log.children("li").length > 8) {
log.get(0).removeChild(log.children("li")[0]);
}
}
function getTime() {
var now = new Date(),
h = now.getHours(),
m = now.getMinutes(),
s = now.getSeconds(),
ms = now.getMilliseconds();
return (h + ":" + m + ":" + s + " " + ms);
}

var newCount = 1;
function addHoverDom(treeId, treeNode) {
var sObj = $("#" + treeNode.tId + "_span");
if (treeNode.editNameFlag || $("#addBtn_" + treeNode.tId).length > 0) return;
var addStr = "<span class='button add' id='addBtn_" + treeNode.tId
+ "' title='add node' onfocus='this.blur();'></span>";
sObj.after(addStr);
var btn = $("#addBtn_" + treeNode.tId);
if (btn) btn.bind("click", function () {
var zTree = $.fn.zTree.getZTreeObj("treeDemo");
var nname = "new node" + (newCount++);
zTree.addNodes(treeNode, { id: (100 + newCount), pId: treeNode.id, name: nname });
Exec(1, 0, nname, treeNode.id);//添加
//alert(treeNode.id + "|" + nname);
return false;
});
};
function removeHoverDom(treeId, treeNode) {
$("#addBtn_" + treeNode.tId).unbind().remove();
};
function selectAll() {
var zTree = $.fn.zTree.getZTreeObj("treeDemo");
zTree.setting.edit.editNameSelectAll = $("#selectAll").attr("checked");
}

$(document).ready(function () {
var zNodes = $.parseJSON($("#json").val());
$.fn.zTree.init($("#treeDemo"), setting, zNodes);
$("#selectAll").bind("click", selectAll);
});

function Exec(type, id, name, parent) {
$.post("/zTree_v3/Alter.ashx", {"type":type,"id": id, "name": name, "pid": parent }, function (data) {
alert(data);
});
}
</script>
<style type="text/css">
.ztree li span.button.add {margin-left:2px; margin-right: -1px; background-position:-144px 0; vertical-align:top; *vertical-align:middle}
</style>
</head>
<body>
<input type="hidden" id="json" runat="server" />
<form id="form1" runat="server">
<div>
<ul id="treeDemo" class="ztree"></ul>
</div>
</form>
</body>
</html>

一般处理程序

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebTest.zTree_v3
{
/// <summary>
/// Alter 的摘要说明
/// </summary>
public class Alter : IHttpHandler
{

public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
Department de=new Department();
string result=string.Empty;
int type = int.Parse( context.Request["type"].ToString());
if (type == 1)//添加信息
{
de.Name=context.Request["name"];
de.ParentId=int.Parse(context.Request["pid"].ToString());
result=AddDep(de);
}
else if (type == 2)//修改名称
{
de.Id=int.Parse(context.Request["id"].ToString());
de.Name=context.Request["name"];
result= AltDep(de);
}
else if (type == 3)//修改所属上级
{
de.Id=int.Parse(context.Request["id"].ToString());
de.ParentId=int.Parse(context.Request["pid"].ToString());
result=AltPar(de);
}
else if (type == 4)//删除
{
de.Id=int.Parse(context.Request["id"].ToString());
result = DelDep(de);
}
context.Response.Write(result);
}
private string AddDep(Department de)
{
return QueryData.ExecSQL("insert into Department(name,parent) values('"+de.Name+"','"+de.ParentId+"')");
}
private string AltDep(Department de)
{
return QueryData.ExecSQL("update Department set name='"+de.Name+"' where id="+de.Id);
}
private string AltPar(Department de)
{
return QueryData.ExecSQL("update Department set parent=" + de.ParentId + " where id=" + de.Id);
}
private string DelDep(Department de)
{
return QueryData.ExecSQL("delete Department where id=" + de.Id);
}
public bool IsReusable
{
get
{
return false;
}
}
public class Department
{
public int ParentId{get;set;}
public string Name{get;set;}
public int Id{get;set;}
}
}
}

表结构

最终效果

zTree v3.5配置的更多相关文章

  1. JQuery Ztree 树插件配置与应用小结

    JQuery Ztree 树插件配置与应用小结 by:授客 QQ:1033553122 测试环境 Win7 jquery-3.2.1.min.js 下载地址: https://gitee.com/is ...

  2. 备忘-zTree v3.5 Demo 演示

    zTree v3.5 Demo 演示: http://www.ztree.me/v3/demo.php#_110

  3. springmvc+ztree v3实现类似表单回显功能

    在做权限管理系统时,可能会用到插件zTree v3,这是一个功能丰富强大的前端插件,应用很广泛,如异步加载菜单制作.下拉选择.权限分配等.在集成SpringMVC中,我分别实现了zTree的添删改查, ...

  4. zTree V3 是个好东西 功能很强大

    zTree V3 是个好东西 功能很强大 地址:http://www.ztree.me/v3/demo.php#_101

  5. Gitolite v3安装配置指南

    使用gitolite对git仓储进行权限配置 gitolite在近期做了很多代码改动,升级到了v3版本,而我使用的是v3.5.2.在<Git权威指南>中所提及的是v2版本,有很多东西已经不 ...

  6. jQuery zTree v3.5 实例3 异步树

    最终效果: 点击非叶子节点时,向后台发送请求,获取下级菜单 前台代码如下: <%@ page language="java" contentType="text/h ...

  7. jquery Ztree v3.5 实例2 自定义显示在节点前的图片

    显示效果如下: 代码如下: <html> <head><title></title></head> <script type=&quo ...

  8. angular ztree 梯形结构json配置、点击节点事件、默认展开所有

    // 获取树数据 $scope.initZtreeData = function () { var url = '/bpopstation/func/queryAll.do'; $http.post( ...

  9. 在java中如何使用etcd的v2 和v3 api获取配置,并且对配置的变化进行监控

    etcd 和zookeeper 很像,都可以用来做配置管理.并且etcd可以在目前流行的Kubernetes中使用. 但是etcd 提供了v2版本合v3的版本的两种api.我们现在分别来介绍一下这两个 ...

随机推荐

  1. espcms自定义表单邮件字段

    /include/inc_replace_mailtemplates.php中增加一行就可以了. 如:$replacemail['mailform'][] = array(name => '职位 ...

  2. JSONP跨域的原理解析

    JavaScript是一种在Web开发中经常使用的前端动态脚本技术.在JavaScript中,有一个很重要的安全性限制,被称为“Same- Origin Policy”(同源策略).这一策略对于Jav ...

  3. subprocess模块在Windows下调用失败问题

    bug of pythonhttp://bugs.python.org/issue1759845 解决:print sys.stdout.encoding  #eg : it shows cp936i ...

  4. oracle,mybatis主键自增长

    <insert id="insert" parameterType="resource"> <selectKey resultType=&qu ...

  5. Android开发者必备的42个链接

    http://mobile.51cto.com/ahot-426035.htm Android开发者必备的42个链接 下面收集了42个帮助大家学习Android的内容链接,部分内容是面向初学者的,帮助 ...

  6. sprinvMVC路径拦截

    关于这种路径的拦截: http://localhost:8080/moodleCourse-tool/scorm/23681/mod_scorm/content/1/index_SCORM.html ...

  7. 【编程题目】题目:定义 Fibonacci 数列 输入 n,用最快的方法求该数列的第 n 项。

    第 19 题(数组.递归):题目:定义 Fibonacci 数列如下:/ 0 n=0f(n)= 1 n=1/ f(n-1)+f(n-2) n=2输入 n,用最快的方法求该数列的第 n 项. 思路:递归 ...

  8. C#导出Excel动态列

    一.用StreamWrite流对象,导出Excel 1. string _sPath = GenerateSalaryMonthlyReport(dgvSalarySum); System.Diagn ...

  9. C#实现把指定文件夹下的所有文件复制到指定路径下以及修改指定文件的后缀名

    1.实现把指定文件夹下的所有文件复制到指定路径下 public static void copyFiles(string path) { DirectoryInfo dir = new Directo ...

  10. 存储过程使用CTE 和 case when

    未用SQL CTE and case when: ALTER PROCEDURE [dbo].[usp_rptDropboxBatchSummary1] )='ALL', )='ALL', )='AL ...