EasyUI tree 选中父节点子节点全部选中,选中子节点父节点不选中

需求:EasyUI tree 选中父节点子节点全部选中,选中子节点父节点不选中

效果:

          

  1.  
    /**
  2.  
    * 给树增加onCheck事件,首先使用cascadeCheck:false属性禁止全选,
  3.  
    * 然后获取当前选中节点的所有子节点,在判断其拥有子节点时对其所有字节点
  4.  
    * 进行遍历操作。在easyui中树节点的是否选中不是由checked:true
  5.  
    * 属性来控制,而是由class tree-checkbox0
  6.  
    * 和tree-checkbox1进行控制。--by wk
  7.  
    */
  8.  
    cascadeCheck: false,//取消勾选属性
  9.  
    onCheck: function(node, checked){
  10.  
    var childList = $(this).tree('getChildren',node.target);
  11.  
    if(childList.length>0){
  12.  
    var checkedTrue = function(){
  13.  
    childList.map( function(currentValue){
  14.  
    $( "div[node-id='"+currentValue.id+"']").find(".tree-checkbox").removeClass("tree-checkbox0").addClass("tree-checkbox1");
  15.  
    })
  16.  
    };
  17.  
    var checkedFalse = function(){
  18.  
    $.each(childList, function(index,currentValue){
  19.  
    $( "div[node-id='"+currentValue.id+"']").find(".tree-checkbox").removeClass("tree-checkbox1").addClass("tree-checkbox0");
  20.  
    })
  21.  
    };
  22.  
    var checkChangeProperties = checked==true ? checkedTrue() : checkedFalse();
  23.  
    }
  24.  
    }

猜你喜欢

转载自www.cnblogs.com/wangluochong/p/9374925.html