fullcalendar存在两个问题

huangapple go评论57阅读模式
英文:

Two Problems with fullcalendar

问题

我有两个关于fullcalendar的问题,我无法解决。

第一个问题是,当我添加或更新事件时,我调用refetchEvents()函数,但它在控制台上给我以下错误,并且不更新事件:

Uncaught TypeError: Cannot read properties of undefined (reading 'refetchEvents')

我调用refetchEvents()的代码如下:

function agregarRegistro(registro) {
    $.ajax({
        type: 'POST',
        url: 'datoseventos.php?accion=agregar',
        data: registro,
        success: function(msg) {
            calendario1.refetchEvents();
        },
        error: function(error) {
            calendario1.refetchEvents();
        }
    });
}

其中calendario1 被调用如下:

var calendario1;
document.addEventListener('DOMContentLoaded', function() {
    var calendarEl = document.getElementById('calendario1');
    var taller = '<?php echo $tare;?>';
    var user = '<?php echo $ctrl_user;?>';
    var userfiltro = '0';
    var calendario1 = new FullCalendar.Calendar(calendarEl, {
        // 其他配置项...
    });
});

第二个错误是当我加载约会(来自数据库)时。问题是约会加载得很好,但时间显示不正确。例如,如果约会在6月16日07:00开始,我从数据库中确实收到了这个时间:

{"allDay":false,"title":"yyyyyyyy","start":"2023-06-16T07:00:00Z","end":"2023-06-16T10:00:00Z","id":"8281","backgroundColor":"#FFFF00","textColor":"#ffffff","extendedProps":{"descripcion":"","idtra":"0","iduser":"88","tipo_parte":"0"}}

然而,在模态框的时间选择器中,我得到了09:00。如果我通过控制台打印它,它也给我9。

LA HORA ES 09:00

我的模态框代码如下:

<div class="modal fade" id="FormularioEventos" tabindex="-1" role="dialog">
    <!-- 其他模态框内容... -->
</div>

JavaScript代码如下:

eventClick: function(info) {
    // 其他处理...
    console.log("LA HORA ES " + moment(info.event.start).format("HH:mm"));
    // 其他处理...
    $("#FormularioEventos").modal();
}

请注意,这只是提供给您的代码的翻译部分,没有其他内容。

英文:

I have two problems with fullcalendar that I can't solve.

The first is that when I add or update an event, I call the refetchEvents() function but it gives me the following error on the console and doesn't update the events:

Uncaught TypeError: Cannot read properties of undefined (reading &#39;refetchEvents&#39;)

The code where I call refetchEvents():

function agregarRegistro(registro) {
            $.ajax({
                type: &#39;POST&#39;,
                url: &#39;datoseventos.php?accion=agregar&#39;,
                data: registro,
                success: function(msg) {
                    calendario1.refetchEvents();
                },
                error: function(error) {
                    //alert(&quot;Hay un problema:&quot; + error);
                    calendario1.refetchEvents();
                }
            });
        }

Where calendario1 is called:

    var calendario1;
document.addEventListener(&#39;DOMContentLoaded&#39;, function() {
  var calendarEl = document.getElementById(&#39;calendario1&#39;);
            var taller = &#39;&lt;?php echo $tare;?&gt;&#39;
            var user = &#39;&lt;?php echo $ctrl_user;?&gt;&#39;
            var userfiltro = &#39;0&#39;
  var calendario1 = new FullCalendar.Calendar(calendarEl, {
    timeZone: &#39;UTC&#39;,
    schedulerLicenseKey: &#39;CC-Attribution-NonCommercial-NoDerivatives&#39;,
    initialView: &#39;resourceTimelineDay&#39;,
    aspectRatio: 1.5,
    locale: &#39;es&#39;,
    headerToolbar: {
      left: &#39;prev,next&#39;,
      center: &#39;title&#39;,
      right: &#39;resourceTimelineDay,resourceTimelineWeek,resourceTimelineMonth&#39;
    },
    editable: true,
    resourceAreaHeaderContent: &#39;Rooms&#39;,
    resources: &#39;datoseventos.php?accion=listarempleados&amp;taller=&#39; + taller + &#39;&amp;user=&#39; + user + &#39;&amp;user_filtro=&#39; +userfiltro,
    //resources: &#39;https://fullcalendar.io/api/demo-feeds/resources.json?with-nesting&amp;with-colors&#39;,
   events: &#39;datoseventos.php?accion=listar&amp;taller=&#39; + taller + &#39;&amp;user=&#39; + user + &#39;&amp;user_filtro=&#39; +userfiltro,

The second error is when I load the appointments (From a database). The problem is that the appointment loads fine, but the time is not displayed correctly. For example, if the appointment starts on June 16 at 07:00 I correctly receive this from the database:

 {&quot;allDay&quot;:false,&quot;title&quot;:&quot;yyyyyyyy&quot;,&quot;start&quot;:&quot;2023-06-16T07:00:00Z&quot;,&quot;end&quot;:&quot;2023-06-16T10:00:00Z&quot;,&quot;id&quot;:&quot;8281&quot;,&quot;backgroundColor&quot;:&quot;#FFFF00&quot;,&quot;textColor&quot;:&quot;#ffffff&quot;,&quot;extendedProps&quot;:{&quot;descripcion&quot;:&quot;&quot;,&quot;idtra&quot;:&quot;0&quot;,&quot;iduser&quot;:&quot;88&quot;,&quot;tipo_parte&quot;:&quot;0&quot;}}

However, in the time selector of the modal, I get 09:00. If I print it through the console, it also gives me 9.

LA HORA ES 09:00

My Modal:

    &lt;div class=&quot;modal fade&quot; id=&quot;FormularioEventos&quot; tabindex=&quot;-1&quot; role=&quot;dialog&quot;&gt;
&lt;div class=&quot;modal-dialog&quot; role=&quot;document&quot;&gt;
&lt;div class=&quot;modal-content&quot;&gt;
&lt;div class=&quot;modal-header&quot;&gt;
&lt;button type=&quot;button&quot; class=&quot;close&quot; data-dismiss=&quot;modal&quot; aria-label=&quot;Close&quot;&gt;
&lt;span aria-hidden=&quot;true&quot;&gt;&amp;times;&lt;/span&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;modal-body&quot;&gt;
&lt;input type=&quot;hidden&quot; id=&quot;Codigo&quot;&gt;
&lt;input type=&quot;hidden&quot; id=&quot;idveh&quot;&gt;
&lt;input type=&quot;hidden&quot; id=&quot;tiempocita&quot; value=&quot;60&quot;&gt;
&lt;div class=&quot;form-row&quot;&gt;
&lt;div class=&quot;form-group col-md-12&quot;&gt;
&lt;label&gt;Titulo de la Cita:&lt;/label&gt;
&lt;input type=&quot;text&quot; id=&quot;Titulo&quot; class=&quot;form-control&quot; placeholder=&quot;&quot;&gt;
&lt;input type=&quot;hidden&quot; id=&quot;idtall&quot; name=&quot;idtall&quot; value=&quot;&lt;?php echo $tare ?&gt;&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;form-row&quot;&gt;
&lt;div class=&quot;form-group col-md-12&quot;&gt;
&lt;label&gt;Empleado que ejecuta el trabajo:&lt;/label&gt;
&lt;?php
$comprobar_user = mysqli_query($mysqli,&quot;SELECT * FROM usuarios WHERE id_empresa = &#39;$id_empresa&#39; AND idtaller = &#39;$tare&#39;&quot;);
echo &quot;&lt;select class=&#39;custom-select&#39; name=&#39;iduser&#39; id=&#39;iduser&#39;&gt;&quot;;
?&gt;
&lt;option value=&#39;0&#39; &lt;?php if($ctrl_user == 0){ echo &quot;selected&quot;; } ?&gt;&gt;Todos&lt;/option&gt;
&lt;?php
while ($fila1=mysqli_fetch_array($comprobar_user)) {
echo &quot;&lt;option  value=&#39;&quot;.$fila1[&quot;id&quot;].&quot;&#39; &quot;.$marcaidtaller.&quot;&gt;&quot;.$fila1[&quot;nombre&quot;].&quot; &lt;/option&gt;&quot;;
}
echo &quot;&lt;/select&gt;&quot;;
?&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;form-row&quot;&gt;
&lt;div class=&quot;form-group col-md-6&quot;&gt;
&lt;label&gt;Fecha de Inicio:&lt;/label&gt;
&lt;div class=&quot;input-group&quot; data-autoclose=&quot;true&quot;&gt;
&lt;input type=&quot;date&quot; id=&quot;FechaInicio&quot; value=&quot;&quot; class=&quot;form-control&quot; /&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;form-group col-md-6&quot; id=&quot;TituloHoraInicio&quot;&gt;
&lt;label&gt;Hora de inicio:&lt;/label&gt;
&lt;div class=&quot;input-group clockpicker&quot; data-autoclose=&quot;true&quot;&gt;
&lt;input type=&quot;text&quot; id=&quot;HoraInicio&quot; value=&quot;&quot; class=&quot;form-control&quot; autocomplete=&quot;off&quot; /&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;form-row&quot;&gt;
&lt;div class=&quot;form-group col-md-6&quot;&gt;
&lt;label&gt;Fecha de Fin:&lt;/label&gt;
&lt;div class=&quot;input-group&quot; data-autoclose=&quot;true&quot;&gt;
&lt;input type=&quot;date&quot; id=&quot;FechaFin&quot; value=&quot;&quot; class=&quot;form-control&quot; /&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;form-group col-md-6&quot; id=&quot;TituloHoraFin&quot;&gt;
&lt;label&gt;Hora de fin:&lt;/label&gt;
&lt;div class=&quot;input-group clockpicker&quot; data-autoclose=&quot;true&quot;&gt;
&lt;input type=&quot;text&quot; id=&quot;HoraFin&quot; value=&quot;&quot; class=&quot;form-control&quot; autocomplete=&quot;off&quot; /&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;form-group&quot;&gt;
&lt;label&gt;Descripcion :&lt;/label&gt;
&lt;textarea id=&quot;Descripcion&quot; rows=&quot;3&quot; class=&quot;form-control&quot;&gt;&lt;/textarea&gt;
&lt;/div&gt;
&lt;div class=&quot;form-group&quot;&gt;
&lt;label&gt;Color de Fondo:&lt;/label&gt;
&lt;select id=&quot;ColorFondo&quot; class=&quot;form-control&quot; style=&quot;height:36px;&quot;&gt;
&lt;option value=&quot;#0000FF&quot; id=&quot;option-1&quot; selected&gt;Azul&lt;/option&gt;
&lt;option value=&quot;#00008B&quot; id=&quot;option-6&quot;&gt;Azul Oscuro&lt;/option&gt;
&lt;option value=&quot;#FFFF00&quot; id=&quot;option-5&quot;&gt;Amarillo&lt;/option&gt;
&lt;option value=&quot;#808080&quot; id=&quot;option-4&quot;&gt;Gris&lt;/option&gt;
&lt;option value=&quot;#00FF00&quot; id=&quot;option-10&quot;&gt;Lima&lt;/option&gt;
&lt;option value=&quot;#FFA500&quot; id=&quot;option-8&quot;&gt;Naranja&lt;/option&gt;
&lt;option value=&quot;#000000&quot; id=&quot;option-9&quot;&gt;Negro&lt;/option&gt;
&lt;option value=&quot;#808000&quot; id=&quot;option-7&quot;&gt;Oliva&lt;/option&gt;
&lt;option value=&quot;#F8B88B&quot; id=&quot;option-12&quot;&gt;Pastel&lt;/option&gt;
&lt;option value=&quot;#FF0000&quot; id=&quot;option-3&quot;&gt;Rojo&lt;/option&gt;
&lt;option value=&quot;#FF00FF&quot; id=&quot;option-11&quot;&gt;Rosa&lt;/option&gt;
&lt;option value=&quot;#008000&quot; id=&quot;option-2&quot;&gt;Verde&lt;/option&gt;
&lt;/select&gt;
&lt;/div&gt;
&lt;div class=&quot;form-group&quot;&gt;
&lt;label&gt;Color de Texto:&lt;/label&gt;
&lt;input type=&quot;color&quot; value=&quot;#ffffff&quot; id=&quot;ColorTexto&quot; class=&quot;form-control&quot; style=&quot;height:36px;&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;modal-footer&quot;&gt;
&lt;button type=&quot;button&quot; id=&quot;BotonAgregar&quot; class=&quot;btn btn-success&quot;&gt;Agregar&lt;/button&gt;
&lt;button type=&quot;button&quot; id=&quot;BotonModificar&quot; class=&quot;btn btn-success&quot;&gt;Modificar&lt;/button&gt;
&lt;a href=&quot;javascript:void(0)&quot; target=&quot;_blank&quot; id=&quot;BotonOt&quot; class=&quot;btn btn-success&quot;&gt;Abrir Parte&lt;/a&gt;
&lt;button type=&quot;button&quot; id=&quot;BotonBorrar&quot; class=&quot;btn btn-success&quot;&gt;Borrar&lt;/button&gt;
&lt;button type=&quot;button&quot; class=&quot;btn btn-success&quot; data-dismiss=&quot;modal&quot;&gt;Cancelar&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

JS:

eventClick: function(info) {
console.log(&quot;EL RES ES &quot;+JSON.stringify(info.event));
console.log(&quot;LA HORA ES &quot;+moment(info.event.start).format(&quot;HH:mm&quot;));
$(&#39;#BotonModificar&#39;).show();
if (info.event.extendedProps.idtra != 0) {
if (info.event.extendedProps.tipo_parte != 0) {
$(&#39;#BotonOt&#39;).attr(&quot;href&quot;, &quot;./modifica_parte_contado.php?id=&quot; + info.event.extendedProps.idtra).show();
} else {
$(&#39;#BotonOt&#39;).attr(&quot;href&quot;, &quot;./modifica_parte_cia.php?id=&quot; + info.event.extendedProps.idtra).show();
}
} else {
$(&#39;#BotonOt&#39;).hide();
}
$(&#39;#BotonBorrar&#39;).show();
$(&#39;#BotonAgregar&#39;).hide();
$(&#39;#Codigo&#39;).val(info.event.id);
$(&#39;#iduser&#39;).val(info.event.extendedProps.iduser);
$(&#39;#idtra&#39;).val(info.event.idtra);
$(&#39;#Titulo&#39;).val(info.event.title);
$(&#39;#Descripcion&#39;).val(info.event.extendedProps.descripcion);
$(&#39;#FechaInicio&#39;).val(moment(info.event.start).format(&quot;YYYY-MM-DD&quot;));
$(&#39;#FechaFin&#39;).val(moment(info.event.end).format(&quot;YYYY-MM-DD&quot;));
$(&#39;#HoraInicio&#39;).val(moment(info.event.start).format(&quot;HH:mm&quot;));
$(&#39;#HoraFin&#39;).val(moment(info.event.end).format(&quot;HH:mm&quot;));
$(&#39;#ColorFondo&#39;).val(info.event.backgroundColor);
$(&#39;#ColorTexto&#39;).val(info.event.textColor);
$(&quot;#FormularioEventos&quot;).modal();
},

答案1

得分: 1

首先,感谢大家的帮助。对于可能需要的人:

1)-显示错误时间的问题:

我只是将这个更改了:

timeZone: &#39;UTC&#39;,

改成了:

timeZone: &#39;local&#39;,

2)-refetchEvents()没有起作用的问题:

我实施了这个更改,我删除了调用中的VAR,原本是这样的:

var calendario1 = new FullCalendar.Calendar(calendarEl, {

现在变成了:

calendario1 = new FullCalendar.Calendar(calendarEl, {
英文:

First of all, thank you all for your help. For who may need it:

1)-The problem that the wrong time was displayed:

I just changed this:

timeZone: &#39;UTC&#39;,

For this:

timeZone: &#39;local&#39;,

2)-The problem that refetchEvents() did not serve:

I implemented I removed the VAR in the call, which was like this:

var calendario1 = new FullCalendar.Calendar(calendarEl, {

and it was like this:

calendario1 = new FullCalendar.Calendar(calendarEl, {

huangapple
  • 本文由 发表于 2023年6月16日 13:44:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76487264.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定