zoukankan      html  css  js  c++  java
  • TreePanel checkbox 联动

    经典的checkbox树默认是不会有联动处理的。这里变量INDEX_CATEGORY_CHECKING是为了避免各个节点事件触发后的递归调用,从而解决了过多递归的问题。

    代码
    'checkchange'function(node, checked){

        
    if (!INDEX_CATEGORY_CHECKING) {
            INDEX_CATEGORY_CHECKING 
    = true;

            
    // true时,子同父,父也同子
            if (checked == true) {
                node.attributes.checked 
    = true;

                
    // 父变为true,所有子都跟着变化
                (function(node) {
                    
    var _this = arguments.callee;
                    
    if (!node.isLeaf()) {
                        node.expand();
                        node.eachChild(
    function(child) {
                            child.ui.toggleCheck(
    true);
                            child.attributes.checked 
    = true;
                            _this.call(_this, child);
                        });
                    }
                 })(node);

                
    // 父变为true,父的父(如果有的话)也应该都为true
                (function(node) {
                    
    var _this = arguments.callee;
                    
    if (node.parentNode && node.parentNode != t.root) {
                        
    var pnode = node.parentNode;
                        pnode.ui.toggleCheck(
    true);
                        pnode.attributes.checked 
    = true;
                        _this.call(_this, pnode);
                    }
                 })(node);

            } 
    else { // false 时,子同父,但父不一定同子
                node.attributes.checked = false;

                
    // 父变为false,所有子跟着变化
                (function(node) {
                    
    var _this = arguments.callee;
                    
    if (!node.isLeaf()) {
                        node.expand();
                        node.eachChild(
    function(child) {
                            child.ui.toggleCheck(
    false);
                            child.attributes.checked 
    = false;
                            _this.call(_this, child);
                        });
                    }
                 })(node);

                
    // 父变为false,但父的父(如果有的话)不一定变化
                (function(node) {
                    
    var _this = arguments.callee;
                    
    if (node.parentNode && node.parentNode != t.root) {
                        
    var pnode = node.parentNode;

                        
    var chk = false;
                        pnode.eachChild(
    function(child) {
                            
    if (child.attributes.checked == true) {
                                chk 
    = true;
                                
    return false;
                            }
                        });
                        
    if (chk == true) {
                            
    return;
                        } 
    else {
                            pnode.ui.toggleCheck(
    false);
                            pnode.attributes.checked 
    = false;
                            _this.call(_this, pnode);
                        }
                    }
                 })(node);
            }

            INDEX_CATEGORY_CHECKING 
    = false;
        }
    }
     
  • 相关阅读:
    Gitlab的安装汉化及问题解决
    Python-Day15 JavaScript/DOM
    Python-Day12 Python mysql and ORM
    Python-Day11 RabbitMQ/redis
    Python-Day9 Paramiko模块/进程/线程/RabbitMQ队列
    Python-Day7 面向对象进阶/异常处理/Socket
    使用CryptoJS解决微信小程序用户信息解密
    How to: Configure an Azure SQL Database firewall using the Azure Portal
    iOS 开发: 自定义相册, 保存多张图片到自定义相册中
    解决iOS8.0以上系统下无法通过代码创建被删除过的同名相册 ( iOS 8 Photos framework: Create a albums with iOS8 )
  • 原文地址:https://www.cnblogs.com/KingStar/p/1755299.html
Copyright © 2011-2022 走看看