nodetree中 前面复选框的去掉插件

extendTreeCheck.js

 /**
* tree方法扩展
* 作者:小雪转中雪
*/
$.extend($.fn.tree.methods, {
/**
* 激活复选框
* @param {Object} jq
* @param {Object} target
*/
enableCheck : function(jq, target) {
return jq.each(function(){
var realTarget;
if(typeof target == "string" || typeof target == "number"){
realTarget = $(this).tree("find",target).target;
}else{
realTarget = target;
}
var ckSpan = $(realTarget).find(">span.tree-checkbox");
if(ckSpan.hasClass('tree-checkbox-disabled0')){
ckSpan.removeClass('tree-checkbox-disabled0');
}else if(ckSpan.hasClass('tree-checkbox-disabled1')){
ckSpan.removeClass('tree-checkbox-disabled1');
}else if(ckSpan.hasClass('tree-checkbox-disabled2')){
ckSpan.removeClass('tree-checkbox-disabled2');
}
});
},
/**
* 禁用复选框
* @param {Object} jq
* @param {Object} target
*/
disableCheck : function(jq, target) {
return jq.each(function() {
var realTarget;
var that = this;
var state = $.data(this,'tree');
var opts = state.options;
if(typeof target == "string" || typeof target == "number"){
realTarget = $(this).tree("find",target).target;
}else{
realTarget = target;
}
var ckSpan = $(realTarget).find(">span.tree-checkbox");
ckSpan.removeClass("tree-checkbox-disabled0").removeClass("tree-checkbox-disabled1").removeClass("tree-checkbox-disabled2");
if(ckSpan.hasClass('tree-checkbox0')){
ckSpan.addClass('tree-checkbox-disabled0');
}else if(ckSpan.hasClass('tree-checkbox1')){
ckSpan.addClass('tree-checkbox-disabled1');
}else{
ckSpan.addClass('tree-checkbox-disabled2')
}
if(!state.resetClick){
$(this).unbind('click').bind('click', function(e) {
var tt = $(e.target);
var node = tt.closest('div.tree-node');
if (!node.length){return;}
if (tt.hasClass('tree-hit')){
$(this).tree("toggle",node[0]);
return false;
} else if (tt.hasClass('tree-checkbox')){
if(tt.hasClass('tree-checkbox-disabled0') || tt.hasClass('tree-checkbox-disabled1') || tt.hasClass('tree-checkbox-disabled2')){
$(this).tree("select",node[0]);
}else{
if(tt.hasClass('tree-checkbox1')){
$(this).tree('uncheck',node[0]);
}else{
$(this).tree('check',node[0]);
}
return false;
}
} else {
$(this).tree("select",node[0]);
opts.onClick.call(this, $(this).tree("getNode",node[0]));
}
e.stopPropagation();
});
} });
}
});

调用方法

 /**
* 禁用树形菜单的复选框
* @param disableChecks
*/
function forbiddenTreeCheck(disableChecks){
var level = 0;
$.each(disableChecks,function(key,item){
level = item.attributes.cj;
if(level == 1 || level == 2 || level == 3){
var node = $("#geologicalmapTableID").tree('find',item.id);
$('#geologicalmapTableID').tree('disableCheck', node.target);// 禁用
}
});
}

树形菜单的初始化

 /**
* 初始化树形菜单
*/
function initgeologicaltreeLoad() {
var url = rootPath+'/jasframework/ycsy/geologicalmaptree.do';
$('#geologicalmapTableID').tree( {
url : url,
lines:true,
checkbox:true,
onBeforeLoad:function(node, param) {
if (node!=null) {
$(this).tree('options').url = url+"?cj="+node.attributes.cj+"&parentid="+encodeURI(encodeURI(node.attributes.parentid))+"&checked="+node.checked;
} else {
$(this).tree('options').url = url;
}
},
onCheck:function(node, checked) {
var nodeName = node.attributes.imagename;
var modelId = listModelName(nodeName);
var backID = judgeNodelContaineModelId(nodeName);
if(checked){
if(backID==null){
createProcessBar();
showPic(node.text,node.attributes.parentid);
setTimeout(function(){
closeProcessBar();
},3000);
}else{
objectActions(backID,"显隐",1);
}
}else{
var ID = getModelID(nodeName);
objectActions(backID,"显隐",0);
// objectActions(ID,"显隐",0);
}
},
onDblClick: function(node){
if(node.attributes.cj=='4'){
// var xTemp1=node.attributes.zxjd;
// var xTemp2=node.attributes.zdjd;
// var yTemp1=node.attributes.zxwd;
// var yTemp2=node.attributes.zdwd;
//
// var longitude =(parseFloat(xTemp1)+parseFloat(xTemp2))/2;
// var latitude =((parseFloat(yTemp1)+parseFloat(yTemp2)))/2;
var elevation1 = node.attributes.elevation;
var longitude= node.attributes.longitude;
var latitude = node.attributes.latitude;
var countheight = countHighlyMethod(longitude,latitude);
var elevation =elevation1 + countheight;
if(longitude==0||latitude==0){
$.messager.alert('警告','抱歉,此图件信息不全');
}else{
// setTimeout(function(){
location1(longitude,latitude,elevation1,'0.000000','-90.0000000');
// },1000);
} }
},
onContextMenu: function(e,node){
e.preventDefault();
onTreeContextMenu(node);
},
onLoadSuccess:function(node, data){
forbiddenTreeCheck(data);
if(node == null){
if(!isfirstLoaded){
rootNodes = data;
initFactoryName(data);
isfirstLoaded = !isfirstLoaded;
}
}else{
var parent = $('#geologicalmapTableID').tree('getParent', node.target);// 获取指定厂区区块节点
if(parent == null){
var children = $('#geologicalmapTableID').tree('getChildren', node.target);// 获取指定厂区区块节点
initAreaName(children);
}
}
}
});
}
05-04 02:41