处理数据,数据格式转化

效果:需要考虑扩展性,比如后面增加一条订单为003饿下面的tab也要增加一个003

001 002 根据上面的数据展示订单号 这是一个tab

对应的订单数据 比如001 有2条数据 这里就展示2条数据

数据:

const dataList = [

    {

        "orderId":"001",

        "name":"书",

        "intro":"书的简介"

    },

    {

        "orderId":"002",

        "name":"笔",

        "intro":"笔的简介"

    },

    {

        "orderId":"003",

        "name":"电脑",

        "intro":"电脑的简介"

    },

    {

        "orderId":"001",

        "name":"书桌",

        "intro":"书桌的简介"

    }

 

 

  const pjson = {};

     const birthdayList = this.dataList;

      for (let i = 0; i < birthdayList.length; i++) {

          if (pjson.hasOwnProperty(birthdayList[i].orderId)) {

            pjson[birthdayList[i].orderId ].push(birthdayList[i]);

          } 

          else {

            //如果不存在

            var v = [];

            v.push(birthdayList[i]);

            pjson[birthdayList[i].orderId] = v;

          }

        }

          console.log(pjson)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章