本帖最后由 cqwcns 于 2020-7-25 12:04 编辑
我现在的代码是这样的,但存在的问题就是相同的年月日没有合并为一个对象。
[JavaScript] 纯文本查看 复制代码 let resultData = res.result.data
let formatData=[]
for (var i = 0; i < resultData.length; i++) {
resultData[i].time = common.funDateFormat(resultData[i].createTime,'H:i');
let years=common.funDateFormat(resultData[i].createTime,'Y');
let monthDays=common.funDateFormat(resultData[i].createTime,'m月d日');
formatData[formatData.length]={years:years,monthDays:monthDays,content:resultData[i]}
}
console.log(formatData);
我希望相同的年月日可以合并为一个对象,同一年月日的内容合并到content中,类似这样:
[JavaScript] 纯文本查看 复制代码 resultData: [{
year: 2020,
monthDay: '7月24日',
content: [{
createTime: 1595550263618,
time:'10:32',
request: 'joo',
requestType: '信息查询'
}, {
createTime: 1595380268698,
time:'12:13',
request: 'tom',
requestType: '工单处理'
}, {
createTime: 1595680264638,
time:'11:28',
request: 'luxi',
requestType: '信息查询'
}]
},{
year: 2020,
monthDay: '7月25日',
content: [{
createTime: 1595550263618,
time:'10:32',
request: 'joo',
requestType: '信息查询'
}, {
createTime: 1595380268698,
time:'12:13',
request: 'tom',
requestType: '工单处理'
}, {
createTime: 1595680264638,
time:'11:28',
request: 'luxi',
requestType: '信息查询'
}]
}
]
提醒,所有年月日时分等数据均来自createTime的时间戳。请各位大哥指教,谢谢。 |