码迷,mamicode.com
首页 > 其他好文 > 详细

obj对象数据归类整理

时间:2020-04-21 15:08:45      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:length   span   http   高尔夫   i++   传奇   meta   lan   function   

两个字段根据id对应整理
 
技术图片
 
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>两个字段根据id对应整理</title>
</head>
<body>
<script>
var data ={
    clation:[
        {name: "高尔夫·纯电", parentid: "21"},
        {name: "宝来·纯电",   parentid: "21"},
        {name: "蔚领C-TREK",  parentid: "1"},
        {name: "高尔夫 · 嘉旅",parentid: "1"},
        {name: "宝来·传奇"  ,parentid: "1"},
        {name: "宝来"   ,parentid: "1"},
        {name: "高尔夫"   ,parentid: "1"},
        {name: "全新一代速腾"   ,parentid: "1"},
        {name: "迈腾"   ,parentid: "2"},
        {name: "CC"   ,parentid: "2"},
        {name: "探歌T-ROC"   ,parentid: "3"},
        {name: "探影TACQUA"   ,parentid: "3"},
        {name: "新迈腾"   ,parentid: "2"},
        {name: "探歌T-ROC"   ,parentid: "3"},
    ],
    level: [
        {id: "3", name: "SUV"},
        {id: "21", name: "新能源"},
        {id: "2", name: "中型车"},
        {id: "1", name: "紧凑车型"},
    ]
}
var clation = data.clation;
var level = data.level;
console.log(data,before) 
var arr = [];
for (var i = 0; i < level.length; i++) {
    if(level[i].id){
        var obj = {};
        obj.title = level[i].name;
        obj.list = clation.filter(function(e){
            return (e.parentid ==level[i].id)
        })
        arr.push(obj)
    } 
}
//反选arr.reverse()
console.log(arr,after)
</script>
</body>
</html>

 

obj对象数据归类整理

标签:length   span   http   高尔夫   i++   传奇   meta   lan   function   

原文地址:https://www.cnblogs.com/liubingyjui/p/12744287.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!