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 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
    • ¥15 错误 LNK2001 无法解析的外部符号
    • ¥50 安装pyaudiokits失败
    • ¥15 计组这些题应该咋做呀
    • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
    • ¥15 让node服务器有自动加载文件的功能
    • ¥15 jmeter脚本回放有的是对的有的是错的
    • ¥15 r语言蛋白组学相关问题
    • ¥15 Python时间序列如何拟合疏系数模型