核心提示:easyui树修改节点选中情况(代码实例)全局变量//是否执行点击事件var isdoOnChecked=true;//点击选中节点,设置该节点的所有子节点都选择function setSonLeaf...
easyui树修改节点选中情况(代码实例)
全局变量 //是否执行点击事件 var isdoOnChecked=true;
//点击选中节点,设置该节点的所有子节点都选择 function setSonLeafAllChecked(node,currenttree){ //是否执行点击事件 isdoOnChecked=false; var childList =currenttree.tree('getChildren',node.target); for(var i= 0;i<childList.length;i++){ currenttree.tree("check", childList[i].target); } } //点击该节点,设置选中节点到顶部节点的所有节点为选中状态 function setLeafToRootChecked(node,currenttree){ //是否执行点击事件 isdoOnChecked=false; var parent =currenttree.tree('getParent', node.target); //获取选中节点的父节点 for (i = 0; i < 10; i++) { //可以视树的层级合理设置I if (parent != null) { currenttree.tree("check", parent.target);//设置父节点选择 var currenNode=currenttree.tree('getParent', parent.target); parent = currenNode; } } } //点击取消该节点,该节点和所有子节点全部取消 function setSonLeafUnChecked(node,currenttree){ isdoOnChecked=false; var childList = currenttree.tree('getChildren',node.target); for(var i= 0;i<childList.length;i++){ currenttree.tree("uncheck", childList[i].target); } }
树
function getExtraPrivilegeTree(id,roleID,type){ //生成菜单树 $('#'+id).tree({ url: '/privilege/getExtraPrivilegeTree.do', lines : true, queryParams:{ "roleID":roleID, "privilegeType":type }, checkbox:true, cascadeCheck:false, onLoadSuccess : function (node, data) { }, onCheck:function(node, checked){ var currenttree=$(this); if(isdoOnChecked){ if(checked){ //如果点击是勾选的情况,设置下一次不执行点击点击事件。 //点击选中,子节点全部选中,父节点也要选中 setSonLeafAllChecked(node,currenttree); setLeafToRootChecked(node,currenttree); //设置点击有效 isdoOnChecked=true; }else{//如果点击是取消,取消当前节点的所有子节点 setSonLeafUnChecked(node,currenttree); //设置点击有效 isdoOnChecked=true; } } }, }); }