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;
        }
    }
     
  • 相关阅读:
    Jmeterif controller 使用
    转载App测试工具大全
    Jmeter 官方在线文档&Android SDK 官方下载地址
    APP自动化之uiautomator2 +python3 UI自动化
    uiautomatorviewer不支持安卓 9.0或以上,提示:"error: obtaining UI hierachy"解决方法
    调查显示:软件开发公司出现“人才荒”
    浅谈Lean UX:我们到底该怎么设计?
    谷歌工程师再次公布Windows漏洞 并称微软很难合作
    灵活运用AppFlood:提高APP eCPM的10个技巧
    Spring Framework 4.0M1发布,支持JDK 8、Java EE 7
  • 原文地址:https://www.cnblogs.com/KingStar/p/1755299.html
Copyright © 2011-2022 走看看