zoukankan      html  css  js  c++  java
  • ztree-拖拽(排序树)

    <!DOCTYPE html>
    <HTML>
    <HEAD>
        <TITLE> ZTREE DEMO - beforeDrag / onDrag / beforeDrop / onDrop</TITLE>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="../../../css/demo.css" type="text/css">
        <link rel="stylesheet" href="../../../css/zTreeStyle/zTreeStyle.css" type="text/css">
        <script type="text/javascript" src="../../../js/jquery-1.4.4.min.js"></script>
        <script type="text/javascript" src="../../../js/jquery.ztree.core.js"></script>
        <script type="text/javascript" src="../../../js/jquery.ztree.excheck.js"></script>
        <script type="text/javascript" src="../../../js/jquery.ztree.exedit.js"></script>
        <SCRIPT type="text/javascript">
            var setting = {
                edit: {
                    drag: {
                        autoExpandTrigger: true,
                        prev: dropPrev,
                        inner: dropInner,
                        next: dropNext
                    },
                    enable: true,
                    showRemoveBtn: false,
                    showRenameBtn: false
                },
                data: {
                    simpleData: {
                        enable: true
                    }
                },
                callback: {
                    beforeDrag: beforeDrag,
                    beforeDrop: beforeDrop,
                    beforeDragOpen: beforeDragOpen,
                    onDrag: onDrag,
                    onDrop: onDrop,
                    onExpand: onExpand
                }
            };
    
            var zNodes =[
                { id:1, pId:0, name:"节点1", open:false},
                { id:11, pId:1, name:"节点1-1"},
                { id:12, pId:1, name:"节点1-2"},
                { id:121, pId:12, name:"节点1-2-1"},
                { id:122, pId:12, name:"节点1-2-2"},
                { id:123, pId:12, name:"节点1-2-3"},        
                { id:3, pId:0, name:"节点3", open:false},
                { id:31, pId:3, name:"节点3-1"},
                { id:32, pId:3, name:"节点3-2"},
                { id:33, pId:3, name:"节点3-3"}
            ];
    
            function dropPrev(treeId, nodes, targetNode) {
                var pNode = targetNode.getParentNode();
                if (pNode && pNode.dropInner === false) {
                    return false;
                } else {
                    for (var i=0,l=curDragNodes.length; i<l; i++) {
                        var curPNode = curDragNodes[i].getParentNode();
                        if (curPNode && curPNode !== targetNode.getParentNode() && curPNode.childOuter === false) {
                            return false;
                        }
                    }
                }
                return true;
            }
            function dropInner(treeId, nodes, targetNode) {
                if (targetNode && targetNode.dropInner === false) {
                    return false;
                } else {
                    for (var i=0,l=curDragNodes.length; i<l; i++) {
                        if (!targetNode && curDragNodes[i].dropRoot === false) {
                            return false;
                        } else if (curDragNodes[i].parentTId && curDragNodes[i].getParentNode() !== targetNode && curDragNodes[i].getParentNode().childOuter === false) {
                            return false;
                        }
                    }
                }
                return true;
            }
            function dropNext(treeId, nodes, targetNode) {
                var pNode = targetNode.getParentNode();
                if (pNode && pNode.dropInner === false) {
                    return false;
                } else {
                    for (var i=0,l=curDragNodes.length; i<l; i++) {
                        var curPNode = curDragNodes[i].getParentNode();
                        if (curPNode && curPNode !== targetNode.getParentNode() && curPNode.childOuter === false) {
                            return false;
                        }
                    }
                }
                return true;
            }
    
            var log, className = "dark", curDragNodes, autoExpandNode;
            function beforeDrag(treeId, treeNodes) {
                className = (className === "dark" ? "":"dark");            
                for (var i=0,l=treeNodes.length; i<l; i++) {
                    if (treeNodes[i].drag === false) {
                        curDragNodes = null;
                        return false;
                    } else if (treeNodes[i].parentTId && treeNodes[i].getParentNode().childDrag === false) {
                        curDragNodes = null;
                        return false;
                    }
                }
                curDragNodes = treeNodes;
                return true;
            }
            function beforeDragOpen(treeId, treeNode) {
                autoExpandNode = treeNode;
                return true;
            }
            function beforeDrop(treeId, treeNodes, targetNode, moveType, isCopy) {
                className = (className === "dark" ? "":"dark");            
                return true;
            }
            function onDrag(event, treeId, treeNodes) {
                console.log("拖拽节点")
                className = (className === "dark" ? "":"dark");
                
            }
            function onDrop(event, treeId, treeNodes, targetNode, moveType, isCopy) {
                className = (className === "dark" ? "":"dark");
                
            }
            function onExpand(event, treeId, treeNode) {
                if (treeNode === autoExpandNode) {
                    className = (className === "dark" ? "":"dark");
                    
                }
            }
            function getTime() {
                var now= new Date(),
                h=now.getHours(),
                m=now.getMinutes(),
                s=now.getSeconds(),
                ms=now.getMilliseconds();
                return (h+":"+m+":"+s+ " " +ms);
            }
    
            function setTrigger() {
                var zTree = $.fn.zTree.getZTreeObj("treeDemo");
                zTree.setting.edit.drag.autoExpandTrigger = $("#callbackTrigger").attr("checked");
            }
            
            $(document).ready(function(){
                $.fn.zTree.init($("#treeDemo"), setting, zNodes);
                $("#callbackTrigger").bind("change", {}, setTrigger);
            });
        </SCRIPT>
    </HEAD>
    
    <BODY>
    <div class="content_wrap">
        <div class="zTreeDemoBackground left">
            <ul id="treeDemo" class="ztree"></ul>
        </div>
    </div>
    </BODY>
    </HTML>

    拖拽几点实现排序

  • 相关阅读:
    [WPF VTK]三维图形开发基础(一)
    WP开发(一)
    [WPF VTK]三维图形开发基础(四)

    WIN8 下IE突然无法打开(管理员权限可打开)
    [WPF VTK]三维图形开发基础(三)
    堆排序、快排的坑
    双向链表之插入
    [WPF VTK]三维图形开发基础(二)
    [转载]Android界面设计学习日志(一)
  • 原文地址:https://www.cnblogs.com/excellencesy/p/11807484.html
Copyright © 2011-2022 走看看