js分组递归显示

<!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>

个人觉得挺实用  记录一下 留着以后再用

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值