【发布时间】:2020-06-15 18:05:25
【问题描述】:
我从 API 收到所有活动和已完成的任务。我想调整此对象以使用 SectionList (React-Native),使用每个日期字段 (dataCadastro)按天分隔。例如https://reactnative.dev/docs/sectionlist
{
active: [
{
id: 1,
dataCadastro: '2020-06-15T14:33:45.4807609+00:00',
status: 1,
description: '',
},
{
id: 2,
dataCadastro: '2020-06-15T15:33:45.4807609+00:00',
status: 1,
description: '',
},
],
completed: [
{
id: 3,
dataCadastro: '2020-05-19T14:33:45.4807609+00:00',
status: 1,
description: '',
},
{
id: 4,
dataCadastro: '2020-05-19T15:33:45.4807609+00:00',
status: 1,
description: '',
}
]
}
这样的结果会很棒:
const dataTest = [
{
title: '2020-06-15', // All tasks for the 15th of June.
data: [
{
id: 1,
dataCadastro: '2020-06-15T14:33:45.4807609+00:00',
status: 1,
description: '',
},
{
id: 2,
dataCadastro: '2020-06-15T15:33:45.4807609+00:00',
status: 1,
description: '',
}
],
}, {...}
];
【问题讨论】:
-
你自己有没有尝试过?
标签: javascript arrays react-native object