json结构更改的方法 把date有数据的分类

  data=[
        {
            "content": "如何走进智障儿童的内心",
            "title": "如何走进智障儿童的内心",
            "second": 27,
            "name": "基础课程",
            "categoryId": 12,
            "courseId": 292,
            "noteId": 143,
            "type": 1,
            "date": "11-23",
            "specialId": 186
        },
        {
            "content": "孩子的安全感,不仅仅是精神需求上,而且是物质上。所以要努力给孩子做一个好榜样。",
            "title": "如何构建孩子的安全感",
            "second": 0,
            "name": "基础课程",
            "categoryId": 5,
            "courseId": 818,
            "noteId": 130,
            "type": 1,
            "date": "11-21",
            "specialId": 172
        },
        {
            "content": "引导儿童学会感恩父母,诚实为人,诚信做事。",
            "title": "【专题总览】引导儿童学会感恩父母、诚实为人、诚信做事",
            "second": 0,
            "name": "基础课程",
            "categoryId": 5,
            "courseId": 817,
            "noteId": 129,
            "type": 1,
            "specialId": 172
        }
    ]
    console.log(data.length);
    var team_date = [];
     var indexs = -1;
    data.forEach(function(i,x){
        console.log(i.date);
        if(i.date){
            var team = {
                aa: '',
                list: []
            }
            indexs++;
            team.date=i.date;
            team.list.push(i);
            team_date.push(team);
        }else{
            team_date[indexs].list.push(i);
        }
    })

  http://jsrun.net/CGiKp/edit 在线案例

posted @ 2017-11-27 18:02  顺其自然²º¹?  阅读(1770)  评论(0编辑  收藏  举报