uni-app处理数组根据时间重组

上代码

let list = [{
					id: 0,
					name: '充值消费金',
					time: 1653533103,
					money: 200
				}, {
					id: 0,
					name: '充值消费金',
					time: 1653189651,
					money: 200
				}, {
					id: 1,
					name: '充值消费金',
					time: 1650941103,
					money: 200
				}, {
					id: 1,
					name: '充值消费金',
					time: 1650941103,
					money: 200
				}],
				alltimeList = [];
			list.map(item => {
				let m = this.$mUtils.formatTime(item.time, 'Y-M');
				let timeList = item //
				let newTimeList = {
					time: '',
					timeList: []
				}
				newTimeList.time = m
				newTimeList.timeList.push(timeList)
				let falg = false;
				//判断相同重组
				alltimeList.map((val, num) => {
					if (m == val.time) {
						val.timeList.push(timeList)
						falg = true
						return
					}
				})
				//没有添加新的日期数组
				if (!falg) {
					alltimeList.push(newTimeList)
				}
			})
			this.list = alltimeList;

最后来张效果图吧

以上有所不理解可以小程序联系我

猜你喜欢

转载自blog.csdn.net/qq_42543264/article/details/125100203