dongshi1880 2014-01-03 15:36
浏览 135
已采纳

根据其他ID参数过滤Fullcalendar事件

I am using the jQuery library Fullcalendar to display events for sports teams from a MYSQL database. I have managed to properly setup a JSON feed which displays all the events in the database.

However, a coach can administrate up to three teams, and each of these teams have their own page with its own calendar. Currently, all events are listed in all calendars. I need some sort of filter to make sure that only events belonging to the right team is displayed in each calendar.

I have given each team a unique URL based on their ID, like this.

http://localhost/master/index.php/team/56

The JSON feed currently outputs this:

{"id":"14","event_id":"8","team":"56","start":"2013-12-16 18:00:00","title":"Mandagsgym","description":"Ivar er trenar","location":"Haukelandshallen","start_time":"18:00:00","end_time":"20:00:00"}

My current jQuery:

var filter_id = $('#filter_id').val(); //a variable with the team ID, 
                                       fetched from a hidden input field

$('#calendar').fullCalendar({
    firstDay:'1',
    defaultView: 'basicWeek',
    height: 400,
    editable: true,
    weekends: false,
    header: 
    {
        left: '',
        center: '',
        right: 'prev,next, month,basicWeek'
    },
    columnFormat: 'ddd d/M',
    allDayDefault: false,
    events: 
    {
        url: 'http://localhost/master/index.php/team/json'
    }
    });

As I see it, I have two options: 1) Find a way to assign the third segment of the URL (the team ID) to the JSON feed PHP function, hence providing the calendars with dynamic JSON feeds.

2) Fetch the team ID from the URL, assign it to a Javascript variable and then do some filtering using the Fullcalendar methods, removing or at least hiding the events from the calendar where the team ID does not match the team ID in the URL.

Both of these proposed approaches are well beyond my relatively limited knowledge. I personally fancy approach nr.2. I would be absolutely delighted if anyone could come up with a solution, as I've been stuck on this problem for days.

  • 写回答

1条回答 默认 最新

  • dsf1222 2014-01-04 14:32
    关注

    I think option two is easiest but not necessarily the best. Use a custom events function to filter your results by team_id and then pass the filtered results to the calendar like this:

    events: function(start,end, callback) {
        $.getJSON('http://localhost/master/index.php/team/json', function(data){
            var eventsToShow = [];
            for(var i=0; i<data.length; i++){
                if(data[i].team == filter_id){
                    eventsToShow.push(data[i]);
                }
            }
            callback(eventsToShow);
        });
    }
    

    In my use of fullcalendar, I use a custom function for the events, but my json feed is also dynamic so that I can specify which users to fetch events for. This allows for a pretty dynamic calendar.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法