简体   繁体   English

如果数据库更改,则全日历自动刷新

[英]Fullcalendar auto refresh if db changes

I'm developing app using Fullcalendar v1. 我正在使用Fullcalendar v1开发应用程序。

I successfully integrate connection to mysql database so my events are loaded from db as json array. 我成功集成了与mysql数据库的连接,因此我的事件从db作为json数组加载。 But my app are going to use more than 2 people in one moment so i need automatically refresh after my db changes. 但是我的应用将在一瞬间使用超过2个人,因此我需要在数据库更改后自动刷新。 If one user remove event, calendar refresh for all other users which see this calendar. 如果一个用户删除了事件,则刷新该日历的所有其他用户的日历。

I have one experimenting script which i made. 我有一个实验脚本。 It works but not as well as i want. 它有效,但不如我所愿。 I know, this script is completely bad but i was frustrated. 我知道,这个脚本完全不好,但是我很沮丧。

<script>
var i = setInterval(function(){
last_id = $.cookie('last_id');

$.get("foo.php", function(data) {
       var id = data;


 if(last_id !== id) {

            $('#calendar').fullCalendar('changeView', 'month');
            $('#calendar').fullCalendar('removeEvents');
            $('#calendar').fullCalendar('refetchEvents');
            $('#calendar').fullCalendar( 'rerenderEvents');



last_id = $.cookie('last_id', data);
 }

 });
},500);
</script>

It works pretty simple ... foo.php loads number of rows. 它的工作非常简单... foo.php加载行数。 If this number is other than last number saved in cookies, calendar will be refreshed. 如果此数字不是保存在cookie中的最后一个数字,则日历将被刷新。

This method has tons of disadvantages and mistakes. 这种方法有很多缺点和错误。 It works only for deleting and creating events. 它仅适用于删除和创建事件。 Not for moving etc. And it is slowing app by getting results every 500ms .. 不用于移动等。它通过每500毫秒获取一次结果来减慢应用程序的速度..

Have you better solution for this ? 您对此有更好的解决方案吗?

I have the similar structure.. get data from DB as JSON... 我有类似的结构..从数据库获取数据作为JSON ...

I make a modal for change a event... 我为更改事件制定了模式...

When i press the button who calls my db to update the event.. 当我按下呼叫我的数据库的按钮来更新事件时。

I use behind... a function on jQuery called ( .trigger('click') ) so.. 我在后面使用...在jQuery上的一个名为(.trigger('click'))的函数是这样。

 $('.fc-prev-button').trigger('click');
 $('.fc-next-button').trigger('click');
  //Hide Modal.. button have a data-dismiss="modal"
 $('#closeEdit').trigger('click');

That's my solutions because when load fullCalendar this call events.. param who get data from my db... so when you change the month this is called again for reload the data and don't load the full month with data.. 那是我的解决方案,因为当加载fullCalendar时,此调用事件..参数从我的数据库中获取数据...因此,当您更改月份时,将再次调用此方法以重新加载数据,而不会加载整个月的数据。

Sorry for my english and i hope to help you, Happy Coding !! 对不起,我的英语,希望对您有所帮助,快乐编码!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM