<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
</head>
<body>
<div id="divhtml"></div>
</body>
</html>
<script>
var zNodes=[
{
"EvalutionId": 1,
"AddUser": "leo.zhao",
"AddType": "Customer Service",
"Evalation": 1,
"TaskEvalScore": [
{
"TaskScoreId": 1,
"TaskEvaluationId": 1,
"Score": 5,
"ScoreType": 1
},
{
"TaskScoreId": 2,
"TaskEvaluationId": 1,
"Score": 5,
"ScoreType": 2
},
{
"TaskScoreId": 3,
"TaskEvaluationId": 1,
"Score": 5,
"ScoreType": 3
}
],
"EvaluationContent": [
{
"EvalConnId": 1,
"PrentId": 0,
"AddUser": "leo.zhao",
"Content": "不错 很好。。。"
},
{
"EvalConnId": 2,
"PrentId": 1,
"AddUser": "leo.zhao",
"Content": "嗯 我也这么觉得"
},
{
"EvalConnId": 5,
"PrentId": 2,
"AddUser": "leo.zhao",
"Content": "必须顶起 我也是这么任务"
},
{
"EvalConnId": 6,
"PrentId": 1,
"AddUser": "leo.zhao",
"Content": "嗯 我也这么觉得"
},
{
"EvalConnId": 7,
"PrentId": 0,
"AddUser": "asdfa",
"Content": "不错 很好。。。"
},
{
"EvalConnId": 9,
"PrentId": 7,
"AddUser": "test",
"Content": "好你妹啊...我看就不行"
},
{
"EvalConnId": 11,
"PrentId": 9,
"AddUser": "test1",
"Content": "你就一sb"
},
{
"EvalConnId": 13,
"PrentId": 7,
"AddUser": "test",
"Content": "不行 个人意见"
},
{
"EvalConnId": 14,
"PrentId": 11,
"AddUser": "test",
"Content": "喷子 嘴痒痒了啊"
}
]
},
{
"EvalutionId": 2,
"AddUser": "amy.xu",
"AddType": "Sales",
"Evalation": 1,
"TaskEvalScore": [
{
"TaskScoreId": 10,
"TaskEvaluationId": 2,
"Score": 5,
"ScoreType": 1
},
{
"TaskScoreId": 11,
"TaskEvaluationId": 2,
"Score": 5,
"ScoreType": 2
},
{
"TaskScoreId": 12,
"TaskEvaluationId": 2,
"Score": 5,
"ScoreType": 3
}
],
"EvaluationContent": [
{
"EvalConnId": 3,
"PrentId": 0,
"AddUser": "leo.zhao",
"Content": "test111"
},
{
"EvalConnId": 4,
"PrentId": 3,
"AddUser": "leo.zhao",
"Content": "test111"
}
]
}
];
var left = 0;
function treeMenu(a) {
this.tree = a || [];
this.groups = {};
};
treeMenu.prototype = {
init: function (PrentId) {
this.group();
return this.getDom(this.groups[PrentId], 0);
},
group: function () {
for (var i = 0; i < this.tree.length; i++) {
if (this.groups[this.tree[i].PrentId]) {
this.groups[this.tree[i].PrentId].push(this.tree[i]);
} else {
this.groups[this.tree[i].PrentId] = [];
this.groups[this.tree[i].PrentId].push(this.tree[i]);
}
}
},
getDom: function (a, j) {
if (!a) { return '' }
var html = "";
left = j == 1 ? left + 2 : left;
for (var i = 0; i < a.length; i++) {
html += '<ul>';
html += '<li style="padding-left:' + left + 'em"><span><q>' + a[i].Content + '</q></span></li>';
html += this.getDom(this.groups[a[i].EvalConnId], 1);
html += '</ul>';
}
left = 0
return html;
}
};
var html="";
for(var i =0;i<zNodes.length;i++)
{
html+=new treeMenu(zNodes[i].EvaluationContent).init(0);
}
document.getElementById("divhtml").innerHTML=html;
</script>
个人觉得挺实用 记录一下 留着以后再用