Sort by date

I have a reaction component that displays a list of Meetings that have occurred in the past.

I try to sort every past meeting so that those that have happened recently in the past will be upstairs.

I check if the meeting has happened in the past, if so, show it. (This works fine)

This is my rendering method:

render(){
let past_meetings = this.store.meetings.map((meeting, i) => {
  if (meeting.scheduled_for < moment.utc( new Date() ).format()){
    return (<MeetingItem meeting={meeting} key={`meeting-${meeting.id}`} />)
  } else {
    return ;
  }
})

return(
  <div className="">
    <div className=""> 
      <h3 className="">Past Meetings</h3>
      <div className="" > 
        {past_meetings}
      </div>
    </div> 

  </div>
  )
 }

At present, meetings are shown as: if this happened in the past, show at the top.

My goal is to make him show the following: if this happened recently, show it at the top.

Tried something like this with lodash.sortBy ():

let sorted_meetings = _.sortBy(past_meetings, function(e){
return - (new Date(e.scheduled_for))
}

no success.

meeting.scheduled_for
// returns 2017-03-03T03:33:00.000Z

tried to compare planned_for, but not very lucky.

This can be done using _ ??? or any other way?

+4
1

sort() reverse()

var sorted_meetings = meetings.sort((a,b) => {
    return new Date(a.scheduled_for).getTime() - 
        new Date(b.scheduled_for).getTime()
}).reverse();
+4

Source: https://habr.com/ru/post/1671173/


All Articles