它是我来自 api 的数据
{
id: '1',
developer: {
name: 'Michelle Stewart',
proff: 'Account',
shortInfo: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,',
mail: 'michellestewart@gmail.com',
phone: '+48 500 400 300',
adress: '65 Lorem St, Warsaw, PL',
company: 'Symu.co',
isOnline: false
},
time: 'Today, 5:32 PM',
devmessages: [
{
time: '10 April 2018',
message: 'Lorem ipsum dolor sit amet, consectetur'
},
{
time: '10 April 2018',
message: 'Lorem ipsum dolor sit amet, consectetur'
},
{
time: '10 April 2018',
message: 'quis nostrud exercitation ullamco laboris'
}
],
usermessages: [
{
time: '10 April 2018',
message: 'Oops ops)',
user: true
},
{
time: '10 April 2018',
message: 'Hi how do you do?',
user: true
},
{
time: '10 April 2018',
message: 'Can u test my code',
user: true
}
],
isUnread: true
},
我有反应组件
<ul className="MessagesField">
{
this.props.data !== '' && this.props.data[0].devmessages.concat(this.props.data[0].usermessages).map((item, index) => {
return <li key={index} className={ item.user ? 'MessageFiled UserMessage' : 'MessageFiled ConversationMessage'}>
<div className="UserAvatar">
<img src={ item.user === true ? this.setUserImg(this.state.userId) : this.setConversationsImg(this.props.data[0].id)}/>
</div>
<div className="MessageBody">
<p>{item.message}</p>
<span>{item.time}</span>
</div>
</li>
})
}
</ul>
现在我有这个结果http://i.prntscr.com/Mk3CwGzhQL2nGRW8_nZ-Cg.png
但我需要按日期对消息进行排序,因为我知道我需要使用 moment.js 解析我的数据,然后按此日期进行下一个排序。我不知道该怎么做。有人可以帮我吗)结果我需要得到 http://i.prntscr.com/neLdi4r3RgS9OEfjtUJOzQ.png按按摩日期排序消息