Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

473
Visualizações
How to display multiple JSON values in full calendar?

I am currently displaying a single JSON object value in the full calendar. I need to display the second JSON object as well.

<script>
$(document).ready(function(){
    var booking_details  = @json($booking_details);

    // I need to display these json values also
    var test  = @json($test);
    

    $("#calander").fullCalendar({
      events: booking_details,
      eventColor: '#FF0000'
    }); 
});
</script>

This is the controller in Laravel:

$booking_details = array();
$bookings = Booking::all();
   
foreach ($bookings as $booking) {

    $booking_details[] = [
       'title'=>$booking->room_number,
       'start'=>$booking->checkin_date,
       'end'=>$booking->checkout_date
    ];
}

// this is testing purpose
$test = array();

foreach ($bookings as $booking) {
   $test[] = [
       'title'=>$booking->room_number,
       'start'=>$booking->checkin_date,
       'end'=>$booking->checkout_date
   ];
}

I'm sending the same data with a different JSON name. I only need how to display multiple JSON object values in the same calendar.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Then you need to add the two arrays of events.

$("#calander").fullCalendar({
    events: booking_details.concat(test),
    eventColor: '#FF0000'
}); 
about 4 years ago · Juan Pablo Isaza Relatório

0

Why not just add all the data to the $booking_details array in the PHP code? But also, $test just contains the exact same data as booking_details, so what's the point? Maybe that's just a poor example in the question, I can't tell?

But anyway if you have two separate sources of data you want to supply as events, you can either

  1. use one array in PHP as I suggested above, or

  2. concatenate them in JavaScript as IT goldman's answer shows, or

  3. you can have them as two separate event feeds, which you can set up in fullCalendar via the eventSources option, e.g.

$("#calander").fullCalendar({
  eventSources: [
    {
      "events": booking_details,
      "color": "red"
    },
    {
      "events": test,
      "color": "blue"
    }
  ],
}); 
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda