[Vuejs]-How to refer to individual elements in the file?

0👍

You can write a filter function to filter by relevant dates.

I just wrote the following script:

function filterEventsByCalenderDates(calenderDates) {
  const jsonData = {
    meta: {
      unremovable: [1],
      types: [
        [1, 'public_holiday'],
        [2, 'day_off'],
        [4, 'birthday'],
        [8, 'meeting'],
        [16, 'other'],
      ],
    },
    events: [
      {
        id: 211,
        starts_at: '2019-03-08',
        ends_at: '2019-03-08',
        memo: 'Международный женский день',
        type: 3,
      },
      {
        id: 212,
        starts_at: '2019-10-07',
        ends_at: '2019-10-07',
        memo: 'День учителя',
        type: 1,
      },
      {
        id: 213,
        starts_at: '2019-10-14',
        ends_at: '2019-10-14',
        memo: 'День защитника Украины',
        type: 3,
      },
      {
        id: 214,
        starts_at: '2019-10-18T14:00:00Z',
        ends_at: '2019-10-18T15:00:00Z',
        memo: 'Созвон с Киевом',
        type: 8,
      },
      {
        id: 215,
        starts_at: '2019-10-18T09:00:00Z',
        ends_at: '2019-10-18T13:15:00Z',
        memo: 'Велопрогулка',
        type: 16,
      },
      {
        id: 216,
        starts_at: '2019-10-22',
        ends_at: '2019-10-22',
        memo: 'Гуляем в парке',
        type: 16,
      },
      {
        id: 217,
        starts_at: '2019-10-28',
        ends_at: '2019-11-03',
        memo: 'Конференция',
        type: 18,
      },
      {
        id: 218,
        starts_at: '2019-11-03T21:43:00Z',
        ends_at: '2019-11-03T21:43:00Z',
        memo: 'Самолёт домой',
        type: 16,
      },
      {
        id: 219,
        starts_at: '2019-11-11',
        ends_at: '2019-11-11',
        memo: 'ДР',
        type: 4,
      },
    ],
  };

  const filteredEvents = jsonData.events.filter(event => {
    // separate date from time
    const date = event.starts_at.split('T')[0];
    // validate if the date is part of selected calenderDates
    return calenderDates.includes(date);
  });

  console.log('filteredEvents', filteredEvents);
}

filterEventsByCalenderDates(['2019-10-22', '2019-11-03']);

Leave a comment