日期:2014-05-16  浏览次数:20352 次

EXTJS学习笔记----EXTJs中带复选框的tree,选中父节点时所有子节点也被选中
 // 当选中父节点时,让其子节点相应选中
               contacterTree.on('checkchange', function(node, checked) {  
                node.expand();  
                node.attributes.checked = checked;  
                node.eachChild(function(child) {  
                    child.ui.toggleCheck(checked);  
                    child.attributes.checked = checked;  
                    child.fireEvent('checkchange', child, checked);  
                });  
            }, contacterTree);   


 





第二种
'checkchange' : function(node, checked) {
       win.treepnl.suspendEvents(false);
       //后加的树展开选中函数,存在递归调用,有待提取。
       node.expand(); 
                   node.attributes.checked = checked;   
                   node.eachChild(function(child) {   
                       child.ui.toggleCheck(checked);   
                       child.attributes.checked = checked;   
                       child.fireEvent('checkchange', child, checked);
                       if(child.hasChildNodes()){
                        child.expand();
                        child.eachChild(function(childs) {   
                        childs.ui.toggleCheck(checked);   
                        childs.attributes.checked = checked;   
                        childs.fireEvent('checkchange', childs, checked);
                          if(childs.hasChildNodes()){
                          childs.expand();
                          childs.eachChild(function(childss) {   
                          childss.ui.toggleCheck(checked);   
                          childss.attributes.checked = checked;   
                          childss.fireEvent('checkchange', childss, checked);
                       });
                         }
                     });
                       }
                   });   





3

'checkchange' : function(node, checked) {
       win.treepnl.suspendEvents(false);
       //后加的树展开选中函数,存在递归调用,有待提取。
       node.expand(); 
       node.attributes.checked = checked;
       node.eachChild(function(child) {   
       		child.ui.toggleCheck(checked);   
            child.attributes.checked = checked;   
            child.fireEvent('checkchange', child, checked);
            if(child.hasChildNodes()){
               child.expand();
               child.eachChild(function(childs) {   
                   childs.ui.toggleCheck(checked);   
                   childs.attributes.checked = checked;   
                   childs.fireEvent('checkchange', childs, checked);
                   if(childs.hasChildNodes()){
                        childs.expand();
                        childs.eachChild(function(childss) {   
                          childss.ui.toggleCheck(checked);   
                          childss.attributes.checked = checked;   
                          childss.fireEvent('checkchange', childss, checked);
                       });   
                   }     
              });            
           }        
      });                    
   }