首页 > 解决方案 > 如何根据日期属性过滤对象

问题描述

我有以下json:


[
  {
    "id": "58b1f024-f9dc-44d3-b07e-9672b5815563",
    "userId": "0fdba3ec-90c2-41d7-9912-904f9d0b415d",
    "appointment_date": "Tue Oct 20 2020",
    "appointment_hour": "10:00 - 11:00",
    "created_at": "2020-10-20T21:03:08.285Z",
    "updated_at": "2020-10-20T21:03:08.285Z"
  },
  {
    "id": "05591548-dbbe-49dc-a852-e887487bf2a6",
    "userId": "ea97c2db-bdb3-4323-a070-91d751aa09b7",
    "appointment_date": "Fri Oct 21 2020",
    "appointment_hour": "14:00 - 15:00",
    "created_at": "2020-10-20T22:08:16.307Z",
    "updated_at": "2020-10-20T22:08:16.307Z"
  },
  {
    "id": "5e57942d-33f6-40a8-aae7-bb84fd4c156e",
    "userId": "ea97c2db-bdb3-4323-a070-91d751aa09b7",
    "appointment_date": "Tue Oct 27 2020",
    "appointment_hour": "20:00 - 21:00",
    "created_at": "2020-10-20T22:08:17.745Z",
    "updated_at": "2020-10-20T22:08:17.745Z"
  },
  {
    "id": "dfc2a605-4e34-4110-8f91-64e618f7c846",
    "userId": "0fdba3ec-90c2-41d7-9912-904f9d0b415d",
    "appointment_date": "Tue Oct 27 2020",
    "appointment_hour": "13:00 - 14:00",
    "created_at": "2020-10-20T22:09:33.587Z",
    "updated_at": "2020-10-20T22:09:33.587Z"
  }
]

我需要在页面上显示这些数据,但要动态计算。例如,如果预约已通过(日期:2020 年 10 月 20 日星期二),那么我应该有一行带有 PASSED APPPOINTMENT HEADER 并且该行内的过滤对象带有已通过的日期

<div class="container">
  <div class="row" *ngFor='let appointment of json'>
    <h1>
      Passed appointment
    </h1>
    
    <div>
      {{ appointment.appointment_date}}
    </div>
  </div>
</div>

如果是今天的日期,那么其他行中的今天的对象。如果它的约会日期是例如下周(2020 年 10 月 27 日星期二:来自示例)或下个月,那么应该在下周或下个月的另一行中显示。这一切如何才能实现?

标签: angular

解决方案


推荐阅读