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 我想在一个软件里添加一个优惠弹窗,应该怎么写代码
  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流