var setting = {
view :{
showIcon:false
},
check: {
enable: true,
chkboxType: { "Y" : "", "N" : "" }
},
data: {
simpleData: {
enable: true
}
},
callback: {
onCheck: zTreeOnCheck
}
};
//获取当前节点的根节点(treeNode为当前节点)
function getCurrentRoot(treeNode){
if(treeNode.getParentNode()!=null){
var parentNode = treeNode.getParentNode();
return getCurrentRoot(parentNode);
}else{
return treeNode;
}
}
/**获取指定节点下的所有选中的子节点数组,ids是传入的新数组**/
function getChildren(ids,treeNode){
if (treeNode.isParent){//是父节点
for(var obj in treeNode.children){
getChildren(ids,treeNode.children[obj]);
}
}else{
if(treeNode.checked){//子节点且被勾选状态
ids.push(treeNode.name);
}
}
return ids;
}
/**节点前面复选框选中事件**/
function zTreeOnCheck(event, treeId, treeNode) {
if(treeNode.checked){//勾选事件
//获取当前勾选节点的最顶层根节点
var currentRootNode=getCurrentRoot(treeNode);
var ids=[];
getChildren(ids,currentRootNode);
console.log(currentRootNode.name+"下勾选的节点集合为:"+ids);
if(ids.length>5){
treeNode.checked=false;
alert(currentRootNode.name+"下勾选的关注指标不能超过5个!!");
}
}
// console.log(treeNode.tId + ", " + treeNode.name + "," + treeNode.checked+"\n");
// var treeObj = $.fn.zTree.getZTreeObj("zhibiao_zTree");
// var currentRootNode=getCurrentRoot(treeNode);
// console.log(currentRootNode.name+"\n");
// var nodes = treeObj.getNodesByFilter(function (node) { return node.level == 0 });
// console.log(nodes);
};
/**提交前检查每个大类下勾选的指标个数是否超过5个**/
function inspecttreeNodesNum(number){
number=number||5;
var treeObj = $.fn.zTree.getZTreeObj("zhibiao_zTree");
var nodes = treeObj.getNodesByFilter(function (node) { return node.level == 0 });
console.log(nodes);
for(var i=0;i<nodes.length;i++){
var currentRootNode=nodes[i];
var ids=[];
getChildren(ids,currentRootNode);
console.log(currentRootNode.name+"下勾选的节点集合为:"+ids);
if(ids.length>number){
alert(currentRootNode.name+"下勾选的关注指标超过5个!!请调整");
return false;
}
}
return true;
}
view :{
showIcon:false
},
check: {
enable: true,
chkboxType: { "Y" : "", "N" : "" }
},
data: {
simpleData: {
enable: true
}
},
callback: {
onCheck: zTreeOnCheck
}
};
//获取当前节点的根节点(treeNode为当前节点)
function getCurrentRoot(treeNode){
if(treeNode.getParentNode()!=null){
var parentNode = treeNode.getParentNode();
return getCurrentRoot(parentNode);
}else{
return treeNode;
}
}
/**获取指定节点下的所有选中的子节点数组,ids是传入的新数组**/
function getChildren(ids,treeNode){
if (treeNode.isParent){//是父节点
for(var obj in treeNode.children){
getChildren(ids,treeNode.children[obj]);
}
}else{
if(treeNode.checked){//子节点且被勾选状态
ids.push(treeNode.name);
}
}
return ids;
}
/**节点前面复选框选中事件**/
function zTreeOnCheck(event, treeId, treeNode) {
if(treeNode.checked){//勾选事件
//获取当前勾选节点的最顶层根节点
var currentRootNode=getCurrentRoot(treeNode);
var ids=[];
getChildren(ids,currentRootNode);
console.log(currentRootNode.name+"下勾选的节点集合为:"+ids);
if(ids.length>5){
treeNode.checked=false;
alert(currentRootNode.name+"下勾选的关注指标不能超过5个!!");
}
}
// console.log(treeNode.tId + ", " + treeNode.name + "," + treeNode.checked+"\n");
// var treeObj = $.fn.zTree.getZTreeObj("zhibiao_zTree");
// var currentRootNode=getCurrentRoot(treeNode);
// console.log(currentRootNode.name+"\n");
// var nodes = treeObj.getNodesByFilter(function (node) { return node.level == 0 });
// console.log(nodes);
};
/**提交前检查每个大类下勾选的指标个数是否超过5个**/
function inspecttreeNodesNum(number){
number=number||5;
var treeObj = $.fn.zTree.getZTreeObj("zhibiao_zTree");
var nodes = treeObj.getNodesByFilter(function (node) { return node.level == 0 });
console.log(nodes);
for(var i=0;i<nodes.length;i++){
var currentRootNode=nodes[i];
var ids=[];
getChildren(ids,currentRootNode);
console.log(currentRootNode.name+"下勾选的节点集合为:"+ids);
if(ids.length>number){
alert(currentRootNode.name+"下勾选的关注指标超过5个!!请调整");
return false;
}
}
return true;
}