So überprüfen Sie innerhalb eines bestimmten Datumsbereichs
P粉494151941
P粉494151941 2023-09-07 20:25:21
0
1
564

Ich habe zwei verschiedene Arrays:

accomodation: [
  {
    id: 1,
    name: "Senator Hotel Fnideq",
    address: "Route de Ceuta, 93100 Fnidek, Morocco",
    checkin: "September 1",
    fullCheckinDate: "2021-09-01",
    checkout: "September 3",
    fullCheckoutDate: "2021-09-03",
    nights: 2,
    mealplan: "Breakfast,Lunch"
  },
  {
    id: 2,
    name: "Kabek Morocco Hotel",
    address: "Omis Juy, 93100 Kabek, Morocco",
    checkin: "September 3",
    fullCheckinDate: "2021-09-03",
    checkout: "September 5",
    fullCheckoutDate: "2021-09-05",
    nights: 2,
    mealplan: "Breakfast,Lunch"
  }
]
experiences: [
        {
            id: 1,
            fullDate: "2021-09-01",
            title: "Arrival",
            itinerary: // []
        },
        {
          id: 2,
          fullDate: "2021-09-02",
          title: "Sightseeing",
          itinerary: // []
        }
    ]

Ich möchte einen Weg finden, die gleichen Daten zwischen Unterkünften und Erlebnissen in einem Objekt zu kombinieren.

myTrips: [
  {
    accomodation: {
      id: 1,
      name: "Senator Hotel Fnideq",
      address: "Route de Ceuta, 93100 Fnidek, Morocco",
      checkin: "September 1",
      fullCheckinDate: "2021-09-01",
      checkout: "September 3",
      fullCheckoutDate: "2021-09-03",
      nights: 2,
      mealplan: "Breakfast,Lunch"
    },
    experiences: {
       id: 1,
       fullDate: "2021-09-01",
       title: "Arrival",
       itinerary: // []
    }
  },
  //... 另一个对象
]

Ich verwende dayjs, um Daten zu verwalten. Wie soll ich mit diesem Problem umgehen?

P粉494151941
P粉494151941

Antworte allen(1)
P粉296080076

const accomodation = [
  {
    id: 1,
    name: "Senator Hotel Fnideq",
    address: "Route de Ceuta, 93100 Fnidek, Morocco",
    checkin: "September 1",
    fullCheckinDate: "2021-09-01",
    checkout: "September 3",
    fullCheckoutDate: "2021-09-03",
    nights: 2,
    mealplan: "Breakfast,Lunch"
  },
  {
    id: 2,
    name: "Kabek Morocco Hotel",
    address: "Omis Juy, 93100 Kabek, Morocco",
    checkin: "September 3",
    fullCheckinDate: "2021-09-03",
    checkout: "September 5",
    fullCheckoutDate: "2021-09-05",
    nights: 2,
    mealplan: "Breakfast,Lunch"
  }
];

const experiences = [
    {
        id: 1,
        fullDate: "2021-09-01",
        title: "Arrival",
        itinerary: []
    },
    {
      id: 2,
      fullDate: "2021-09-02",
      title: "Sightseeing",
      itinerary: []
    }
];

const myTrips = [];
accomodation.map(acc => {
  const experience = experiences.filter(exp => {
  const date = new Date(exp.fullDate);
  return date >= new Date(acc.fullCheckinDate) && date <= new Date(acc.fullCheckoutDate);
});
  myTrips.push({accomodation: acc, experience});
});

console.log(myTrips);
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage