<script>
var ojbArray = [
{name: 'a', age: 18, classId: 1 },
{name: 'b', age: 19, classId: 2 },
{name: 'c', age: 16, classId: 3},
{name: 'e', age: 34, classId: 2},
{name: 'f', age: 22, classId: 1},
{name:'d', age: 26, classId: 1}
];
const ClassObj ={};//定义班级对象
ojbArray.map(item=>{//班级分类
if(ClassObj[item.classId] == undefined ){
ClassObj[item.classId] = new Array();
}
ClassObj[item.classId].push(item);
});
const ClassArr =[];
Object.keys(ClassObj).forEach((item)=>{
var obj = {
classId:item,
classInfo:ClassObj[item]
}
ClassArr.push(obj);//合成渲染的list数组
})
console.log(ClassArr)
alert(JSON.stringify(ClassArr))
</script>