记录:一维数组转多维数组&倒序

128 阅读1分钟

//数据源
this.consumerPhotoData.picList=[
  {
    "year": "2021",
    "month": "2",
    "day": "26",
    "wxOrderNo": "1614305033958",
    "picCount": 4,
    "urlList": [
      {
        "opID": 215,
        "photoURL": "https://wxdemo.huaxincreative.com/images/FastHairCut/392/1614305033958/2021-02-26-10-22-19-397.png",
        "picIndex": 0
      },
      {
        "opID": 216,
        "photoURL": "https://wxdemo.huaxincreative.com/images/FastHairCut/392/1614305033958/2021-02-26-14-54-54-965.png",
        "picIndex": 1
      },
    ]
  },
  {
    "year": "2021",
    "month": "2",
    "day": "24",
    "wxOrderNo": "1614128412420",
    "picCount": 9,
    "urlList": [
      {
        "opID": 208,
        "photoURL": "https://wxdemo.huaxincreative.com/images/FastHairCut/392/1614128412420/2021-02-26-10-01-34-744.jpg",
        "picIndex": 0
      }
    ]
  },
  {
    "year": "2021",
    "month": "2",
    "day": "22",
    "wxOrderNo": "1613963665292",
    "picCount": 4,
    "urlList": [
      {
        "opID": 187,
        "photoURL": "https://wxdemo.huaxincreative.com/images/FastHairCut/392/1613963665292/2021-02-22-11-19-15-761.png",
        "picIndex": 0
      }
    ]
  }
]
export default {

computed: {
        consumerPhotoList() {
        
            if (this.consumerPhotoData) {
                const consumerPhotoList = this.consumerPhotoData.picList.reduce(
                    (acc, cur) => {
                        if (acc[cur.year] === undefined) {
                            acc[cur.year] = [];
                        }

                        acc[cur.year].push(cur);

                        return acc;
                    },
                    {}
                );
				//倒序
                const consumerPhotoListEntries = Object.entries(
                    consumerPhotoList
                ).sort((cur, next) => next[0] - cur[0]);

                console.log(33333333333333222222, consumerPhotoListEntries);

                return consumerPhotoListEntries;
            } else {
                return {};
            }
        }
    }
}