【发布时间】:2014-06-10 20:48:50
【问题描述】:
嘿,我有这样的 json
news
{
title: 'hello world',
body: 'bla bla bla',
publish_date: '2014-04-12'
},
{
title: 'hello world',
body: 'bla bla bla',
publish_date: '2014-04-30'
}
{
title: 'hello world 2',
body: 'bla bla bla',
publish_date: '2015-02-30'
},
{
title: 'hello world 2',
body: 'bla bla bla',
publish_date: '2015-02-17'
},
{
title: 'hello world 2',
body: 'bla bla bla',
publish_date: '2015-05-30'
}
我想按“年”和“月”的“发布日期”对其进行排序,如下所示:
{
2014: [{
04: [{
{
title: 'hello world',
body: 'bla bla bla',
publish_date: '2014-04-12'
},
{
title: 'hello world',
body: 'bla bla bla',
publish_date: '2014-04-30'
}
}]
]}
2015: [{
02: [{
{
title: 'hello world 2',
body: 'bla bla bla',
publish_date: '2015-02-30'
},
{
title: 'hello world 2',
body: 'bla bla bla',
publish_date: '2015-02-17'
},
}],
05: [{
{
title: 'hello world 2',
body: 'bla bla bla',
publish_date: '2015-05-30'
}
]}
}]
}
所以我找到了这个 sort JSON by date 按日期对我的 json 进行排序,然后我得到了这个 http://lodash.com/docs#forEach 运行我的主要 json 但我如何“拆分”日期以便完成它?把它分成几年然后一个月?以及如何“推入”我的新排序 json ?我怎样才能确保每年都不会错过任何一个月? 一个方向或无论如何完成它会很棒:)
非常感谢!
【问题讨论】:
标签: javascript json node.js sorting date