var json = {
"text" : "表格列名称",
"children" : [{
"text" : "序号",
"children" : [{
"text" : "序号一",
"children" : []
},{
"text" : "序号二",
"children" : []
}]
},{
"text" : "名称",
"children" : []
},{
"text" : "项目",
"children" : [{
"text" : "项目一",
"children" : [{
"text" : "项目二",
"children" : []
}]
}]
}]
};
//colspan记录节点的所有叶子节点个数
function getLeafCountTree(json) {
if(json.children.length == 0){
json.colspan = 1;
return 1;
}else{
var leafCount = 0;
for(var i = 0 ; i < json.children.length ; i++){
leafCount = leafCount + getLeafCountTree(json.children[i]);
}
json.colspan = leafCount;
return leafCount;
}
}
getLeafCountTree(json);
|