nodetree中 前面复选框禁用插件
nodetree中 前面复选框的去掉插件
extendTreeCheck.js
1 /** 2 * tree方法扩展 3 * 作者:小雪转中雪 4 */ 5 $.extend($.fn.tree.methods, { 6 /** 7 * 激活复选框 8 * @param {Object} jq 9 * @param {Object} target 10 */ 11 enableCheck : function(jq, target) { 12 return jq.each(function(){ 13 var realTarget; 14 if(typeof target == "string" || typeof target == "number"){ 15 realTarget = $(this).tree("find",target).target; 16 }else{ 17 realTarget = target; 18 } 19 var ckSpan = $(realTarget).find(">span.tree-checkbox"); 20 if(ckSpan.hasClass('tree-checkbox-disabled0')){ 21 ckSpan.removeClass('tree-checkbox-disabled0'); 22 }else if(ckSpan.hasClass('tree-checkbox-disabled1')){ 23 ckSpan.removeClass('tree-checkbox-disabled1'); 24 }else if(ckSpan.hasClass('tree-checkbox-disabled2')){ 25 ckSpan.removeClass('tree-checkbox-disabled2'); 26 } 27 }); 28 }, 29 /** 30 * 禁用复选框 31 * @param {Object} jq 32 * @param {Object} target 33 */ 34 disableCheck : function(jq, target) { 35 return jq.each(function() { 36 var realTarget; 37 var that = this; 38 var state = $.data(this,'tree'); 39 var opts = state.options; 40 if(typeof target == "string" || typeof target == "number"){ 41 realTarget = $(this).tree("find",target).target; 42 }else{ 43 realTarget = target; 44 } 45 var ckSpan = $(realTarget).find(">span.tree-checkbox"); 46 ckSpan.removeClass("tree-checkbox-disabled0").removeClass("tree-checkbox-disabled1").removeClass("tree-checkbox-disabled2"); 47 if(ckSpan.hasClass('tree-checkbox0')){ 48 ckSpan.addClass('tree-checkbox-disabled0'); 49 }else if(ckSpan.hasClass('tree-checkbox1')){ 50 ckSpan.addClass('tree-checkbox-disabled1'); 51 }else{ 52 ckSpan.addClass('tree-checkbox-disabled2') 53 } 54 if(!state.resetClick){ 55 $(this).unbind('click').bind('click', function(e) { 56 var tt = $(e.target); 57 var node = tt.closest('div.tree-node'); 58 if (!node.length){return;} 59 if (tt.hasClass('tree-hit')){ 60 $(this).tree("toggle",node[0]); 61 return false; 62 } else if (tt.hasClass('tree-checkbox')){ 63 if(tt.hasClass('tree-checkbox-disabled0') || tt.hasClass('tree-checkbox-disabled1') || tt.hasClass('tree-checkbox-disabled2')){ 64 $(this).tree("select",node[0]); 65 }else{ 66 if(tt.hasClass('tree-checkbox1')){ 67 $(this).tree('uncheck',node[0]); 68 }else{ 69 $(this).tree('check',node[0]); 70 } 71 return false; 72 } 73 } else { 74 $(this).tree("select",node[0]); 75 opts.onClick.call(this, $(this).tree("getNode",node[0])); 76 } 77 e.stopPropagation(); 78 }); 79 } 80 81 }); 82 } 83 });
调用方法
1 /** 2 * 禁用树形菜单的复选框 3 * @param disableChecks 4 */ 5 function forbiddenTreeCheck(disableChecks){ 6 var level = 0; 7 $.each(disableChecks,function(key,item){ 8 level = item.attributes.cj; 9 if(level == 1 || level == 2 || level == 3){ 10 var node = $("#geologicalmapTableID").tree('find',item.id); 11 $('#geologicalmapTableID').tree('disableCheck', node.target);// 禁用 12 } 13 }); 14 }
树形菜单的初始化
1 /** 2 * 初始化树形菜单 3 */ 4 function initgeologicaltreeLoad() { 5 var url = rootPath+'/jasframework/ycsy/geologicalmaptree.do'; 6 $('#geologicalmapTableID').tree( { 7 url : url, 8 lines:true, 9 checkbox:true, 10 onBeforeLoad:function(node, param) { 11 if (node!=null) { 12 $(this).tree('options').url = url+"?cj="+node.attributes.cj+"&parentid="+encodeURI(encodeURI(node.attributes.parentid))+"&checked="+node.checked; 13 } else { 14 $(this).tree('options').url = url; 15 } 16 }, 17 onCheck:function(node, checked) { 18 var nodeName = node.attributes.imagename; 19 var modelId = listModelName(nodeName); 20 var backID = judgeNodelContaineModelId(nodeName); 21 if(checked){ 22 if(backID==null){ 23 createProcessBar(); 24 showPic(node.text,node.attributes.parentid); 25 setTimeout(function(){ 26 closeProcessBar(); 27 },3000); 28 }else{ 29 objectActions(backID,"显隐",1); 30 } 31 }else{ 32 var ID = getModelID(nodeName); 33 objectActions(backID,"显隐",0); 34 // objectActions(ID,"显隐",0); 35 } 36 }, 37 onDblClick: function(node){ 38 if(node.attributes.cj=='4'){ 39 // var xTemp1=node.attributes.zxjd; 40 // var xTemp2=node.attributes.zdjd; 41 // var yTemp1=node.attributes.zxwd; 42 // var yTemp2=node.attributes.zdwd; 43 // 44 // var longitude =(parseFloat(xTemp1)+parseFloat(xTemp2))/2; 45 // var latitude =((parseFloat(yTemp1)+parseFloat(yTemp2)))/2; 46 var elevation1 = node.attributes.elevation; 47 var longitude= node.attributes.longitude; 48 var latitude = node.attributes.latitude; 49 var countheight = countHighlyMethod(longitude,latitude); 50 var elevation =elevation1 + countheight; 51 if(longitude==0||latitude==0){ 52 $.messager.alert('警告','抱歉,此图件信息不全'); 53 }else{ 54 // setTimeout(function(){ 55 location1(longitude,latitude,elevation1,'0.000000','-90.0000000'); 56 // },1000); 57 } 58 59 60 } 61 }, 62 onContextMenu: function(e,node){ 63 e.preventDefault(); 64 onTreeContextMenu(node); 65 }, 66 onLoadSuccess:function(node, data){ 67 forbiddenTreeCheck(data); 68 if(node == null){ 69 if(!isfirstLoaded){ 70 rootNodes = data; 71 initFactoryName(data); 72 isfirstLoaded = !isfirstLoaded; 73 } 74 }else{ 75 var parent = $('#geologicalmapTableID').tree('getParent', node.target);// 获取指定厂区区块节点 76 if(parent == null){ 77 var children = $('#geologicalmapTableID').tree('getChildren', node.target);// 获取指定厂区区块节点 78 initAreaName(children); 79 } 80 } 81 } 82 }); 83 }