dpxua26604 2019-04-04 19:42
浏览 129

如何将输出JSON中的数据加载到fullCalendar事件

I need to display the schedule of a classroom when I click the buttons of any classroom into the fullCalendar object.

I've already made it to retrieve the schedules when I select a classroom making an ajax call.

This function triggers when I click any of the classroom buttons.

function passVal(id) {
    var calendarioFiltro; //Prepare variable to retrieve DB data

    @foreach($salones as $key => $salon)//This foreach fills a small table of a classroom info
      if(id == '{{$salon->id}}'){
        $('#tb_id').val('{{$salon->id}}');
        $('#tb_nombre').val('{{$salon->nombre}}');
        $('#tb_dimensiones').val('{{$salon->dimensiones}}');
        $('#tb_capacidad').val('{{$salon->capacidad}}');
        $('#tb_costobase').val('{{$salon->costobase}}');
        $('#tb_costomobiliario').val('{{$salon->costo_mobiliario}}');
        $('#tb_descripcion').val('{{$salon->descripcion}}');
      }
    @endforeach

    let url = "salones/seleccionar";//Prepare variables to make an ajax call to my controller and load DB data
    let tb_id = document.getElementById('tb_id').value;//From the small table I have a hidden field to send it to the ajax call for my query
    let parametros;
    let longitud;
    var getEvent = [];

    parametros = {
      "tb_id" : tb_id,//This is the parameter to send
    };

    $.ajax({
            url: url,
            data: parametros,
            success: function (data){//Now the data from the query will end up to an array
              calendarioFiltro = data;
              longitud = calendarioFiltro.length;

              var insertEvents = {};
              for(var i = 0;i <= longitud -1;i++)
                {
                  var titulo = calendarioFiltro[i].nombre;
                  var color = calendarioFiltro[i].color;
                  var hora_inicio = calendarioFiltro[i].hora_inicio;
                  var fecha_inicio = calendarioFiltro[i].fecha_inicio;
                  var hora_fin = calendarioFiltro[i].hora_fin;
                  var fecha_fin = calendarioFiltro[i].fecha_fin;

                    insertEvents =//Prepare a JSON format so I can put it into the Events property of my FullCalendar
                    {
                      title : titulo,
                      backgroundColor: color,
                      borderColor: color,
                      startTime: hora_inicio,
                      startRecur : fecha_inicio,
                      endRecur: fecha_fin,
                      endTime: hora_fin,
                    };
                    getEvent.push(insertEvents);//Store all the events in a array format

                };

            }
      });

}

Next is the definition of the calendar properties. I've tried many functions but not getting success is a bit frustating.

    document.addEventListener('DOMContentLoaded', function() {
    var calendarEl = document.getElementById('calendar');
    var calendar = new FullCalendar.Calendar(calendarEl, {
    plugins: [ 'dayGrid', 'timeGrid','list'],
    header: {
      left: 'dayGridMonth,timeGridWeek,timeGridDay,listWeek',
      center: 'title',
      right: 'prev,next'
    },
    locale: 'es',
    allDay: false,
  })
  calendar.render();
});

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料