js数组两层遍历

11 篇文章 0 订阅
9 篇文章 0 订阅
<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>element-ui</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js"></script>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
</head>

<body>
    <div id="app">
    </div>
    <script>
        new Vue({
            el: "#app",
            data: {
                unlockType: [{
                        code: "A",
                        name1: "APP开门"
                    },
                    {
                        code: "F",
                        name1: "人脸识别"
                    },
                    {
                        code: "P",
                        name1: "语音对讲"
                    },
                    {
                        code: "C",
                        name1: "刷卡开门"
                    },
                    {
                        code: "V",
                        name1: "APP对讲"
                    },
                    {
                        code: "S",
                        name1: "物业开门"
                    },
                    {
                        code: "R",
                        name1: "人证开门"
                    },
                    {
                        code: "B",
                        name1: "小程序开门"
                    },
                    {
                        code: "H",
                        name1: "海X小程序开门"
                    },
                    {
                        code: "W",
                        name1: "手环开门"
                    },
                    {
                        code: "T",
                        name1: "二维码开门"
                    }
                ],

                list: [{
                    num: 0,
                    fdate: "2020-01-04",
                    unlockType: "APP开门",
                    unlockTypeId: "A",

                }, {
                    num: 0,
                    fdate: "2020-01-04",
                    unlockType: "小程序开门",
                    unlockTypeId: "B",

                }, {
                    num: 0,
                    fdate: "2020-01-04",
                    unlockType: "刷卡开门",
                    unlockTypeId: "C",

                }, {
                    num: 0,
                    fdate: "2020-01-04",
                    unlockType: "人脸识别",
                    unlockTypeId: "F",

                }, {
                    num: 0,
                    fdate: "2020-01-04",
                    unlockType: "海X小程序开门",
                    unlockTypeId: "H",

                }, {
                    num: 0,
                    fdate: "2020-01-04",
                    unlockType: "语音对讲",
                    unlockTypeId: "P",

                }, {
                    num: 0,
                    fdate: "2020-01-04",
                    unlockType: "人证开门",
                    unlockTypeId: "R",

                }, {
                    num: 0,
                    fdate: "2020-01-04",
                    unlockType: "物业开门",
                    unlockTypeId: "S",

                }, {
                    num: 0,
                    fdate: "2020-01-04",
                    unlockType: "二维码开门",
                    unlockTypeId: "T",

                }, {
                    num: 0,
                    fdate: "2020-01-04",
                    unlockType: "APP对讲",
                    unlockTypeId: "V",

                }, {
                    num: 0,
                    fdate: "2020-01-04",
                    unlockType: "手环开门",
                    unlockTypeId: "W",

                }, {
                    num: 0,
                    fdate: "2020-01-05",
                    unlockType: "APP开门",
                    unlockTypeId: "A",

                }, {
                    num: 0,
                    fdate: "2020-01-05",
                    unlockType: "小程序开门",
                    unlockTypeId: "B",

                }, {
                    num: 0,
                    fdate: "2020-01-05",
                    unlockType: "刷卡开门",
                    unlockTypeId: "C",

                }, {
                    num: 0,
                    fdate: "2020-01-05",
                    unlockType: "人脸识别",
                    unlockTypeId: "F",

                }, {
                    num: 0,
                    fdate: "2020-01-05",
                    unlockType: "海X小程序开门",
                    unlockTypeId: "H",

                }, {
                    num: 0,
                    fdate: "2020-01-05",
                    unlockType: "语音对讲",
                    unlockTypeId: "P",

                }, {
                    num: 0,
                    fdate: "2020-01-05",
                    unlockType: "人证开门",
                    unlockTypeId: "R",

                }, {
                    num: 0,
                    fdate: "2020-01-05",
                    unlockType: "物业开门",
                    unlockTypeId: "S",

                }, {
                    num: 0,
                    fdate: "2020-01-05",
                    unlockType: "二维码开门",
                    unlockTypeId: "T",

                }],
                series: []
            },
            created() {
                //第一次遍历
                this.unlockType.forEach((item, index) => {
                    //先在数组中建几个对象
                    this.series.push({
                        date: [],
                        data: []
                    });
                    //遍历里再遍历
                    this.list.forEach(i => {
                        //将合适
                        if (item.code === i.unlockTypeId) {
                            this.series[index].date.push(i.fdate);
                            this.series[index].data.push(i.num)
                        }
                    })
                });
                console.log(this.series);
            }
        })
    </script>
</body>

</html>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值