我也不知道说什么标题。。。。

版权声明:博客就当自己记的笔记而已~非常感谢博客大神的帮助,若有无意侵权,请联系我,谢谢 https://blog.csdn.net/qq_32963841/article/details/82910301

开发遇到个这个问题,后台返回的格式如下
在这里插入图片描述
但是设计稿如下:
在这里插入图片描述
后台没给我把总月数拿出来,我需要自己去遍历解决
,方法如下:

onLoad() {
        let _this = this;
        _this.$http.get('/pointRecords')
          .then(res => {
            if (_this.pageNum < res.data.pages) {
              _this.list = _this.list.concat(res.data.list);
            let times = [];
              _this.list.forEach(item => {
                times.push(_this.timeReset(item.createdDate));
              });
              times = [...new Set(times)];
              let newArray = [];
              times.forEach(item => {
                let list = [];
                _this.list.forEach(item2 => {
                  if (_this.timeReset(item) === _this.timeReset(item2.createdDate)) {
                    list.push(item2);
                  }
                });
                newArray.push(list);
              });
              _this.temporary = newArray;//因为是用vue写的,所以这边的temporary是用来循环的
            }  
            ;
          }).
      }

还有方法二:

var mouthArr = [
            {
                createdDate: '1'
            }
        ];
        var data = [
            {
                createdDate: '2018-03',
                id: '1',
                value: '1'
            },
            {
                createdDate: '2018-04',
                id: '2',
                value: '2'
            },
            {
                createdDate: '2018-03',
                id: '3',
                value: '3'
            },
            {
                createdDate: '2018-06',
                id: '4',
                value: '4'
            },
            {
                createdDate: '2018-08',
                id: '5',
                value: '5'
            }
        ];

        for (var j = 0; j < mouthArr.length; j++) {
            if (data.length > 0) {
                if (data[0].createdDate === mouthArr[j].createdDate) {
                    mouthArr[j].dataArr.push(data[0]);
                    data.splice(0, 1);
                } else {
                    var obj = {};
                    obj.dataArr = [];
                    obj.createdDate = data[0].createdDate;
                    obj.dataArr.push(data[0]);
                    mouthArr.push(obj);
                    j = 0;
                    data.splice(0, 1);
                }
            }
        }
        mouthArr.splice(0, 1);
console.log(mouthArr)

猜你喜欢

转载自blog.csdn.net/qq_32963841/article/details/82910301