2

我正在使用jQuery Fullcalendar 插件,它在月视图中效果很好。我现在正在玩周视图。问题是,当我每周来回移动时,它似乎只会在一周的开始是新的一个月时重新获取事件。因此,如果有一个周视图是一个月的 1/2 和新月的 1/2(例如,2012 年 7 月的最后一周,从 7 月 29 日开始但在 8 月 4 日结束),那么它不会t 请求重新获取事件。只有当我再次单击前进并且我在(8 月 5 日 - 8 月 11 日)的那一周时,它才会重新获取事件。

问题是我只在服务器上加载 1 个特定月份的事件(所以我没有加载下个月的前几天)。请参阅下面我在月份和年份中传递的代码,以便我的服务器知道要查询哪些数据。

$.ajax({
  url: '/EventCalendar/GetCalEvents/',
  dataType: 'json',
  data: {
    month: $('#calendar').fullCalendar('getDate').getMonth() + 1,
    year: $('#calendar').fullCalendar('getDate').getUTCFullYear(),
  },
  success: function (data) {
    callback(data.Events);
  }
});

这是设计使然,我真的应该在下个月的第一周返回活动,还是这是一个错误?为什么完整日历不触发事件请求?

4

4 回答 4

1

那是因为您的默认视图设置为Month。加载日历时,它会加载整个月的事件。现在,当您切换到周视图时,它不会加载事件,因为它已经拥有整个月的事件。FullCalendar 智能地获取事件。如果您将默认视图设置为星期或天,如下所示:

defaultView: 'agendaWeek',

您会看到它会分别加载每周的事件。我希望这有帮助。谢谢

于 2012-07-19T13:16:25.330 回答
1

你试过使用$('#calendar').fullCalendar('getView')吗?

这将返回一个包含开始和结束时间的视图对象。您可以传递这些值,而不是传递单个月份和年份,并返回在视图显示的时间范围内发生的所有事件。

更好的是,您可以使用完整日历的功能直接从 json feed中提取。start 和 end 值作为 url 参数自动传递,并且在视图更改时更新事件(例如从一周到一周、一个月到一个月、一天到一天或从任何主视图移动时)。

编辑:重新阅读后,您可能还想尝试将lazyFetching设置为false。

于 2012-07-16T02:26:21.863 回答
1

而不是定义自己的$.ajax(...)功能和设置自己的范围(通过解析.fullCalendar('getDate'))使用内置数据源。然后,您将拥有可见的日历范围作为 ajax 服务器端事件获取的输入。

初始化时设置源.fullCalendar(...)。请参阅有关设置 EventSource$.ajax(...)选项以获取 JSON 日历事件数据的文档。

$('#calendar').fullCalendar({
    // Put your other fullCalendar options here too
    eventSources: [
        {
            url: '/EventCalendar/GetCalEvents/',
            dataType: 'json',
            error: function(jqXHR, textStatus, errorThrown) {
                // Logging any error that occured fetching the events
                if(console && console.error){ console.error(arguments); }

                alert("Couldn't fetch events, check the javascript console error log.");
            }
        }
    ]
});

请求/EventCalendar/GetCalEvents/将包含两个UNIX 时间戳(自 1970 年以来的秒数):

  • start: 第一个可见日的开始(包括)
  • end:最后一个可见日的结束(不包括)
  • _: 一个可选的非静态数字,用作ajax 缓存破坏技术。忽略这一点。

对您的服务器的示例请求

/EventCalendar/GetCalEvents/?start=1262332800&end=1265011200&_=1263178646

start只需解析日期值,并返回与-end范围的任何部分重叠的任何日历事件。

于 2012-07-22T00:36:00.843 回答
0

我认为将数据传递到后端并没有错……数据已传递,这就是我所做的……我是 Fullcalendar 的新手……这对我有用……

 eventSources:
       [

           // your event source
               {

                   url: '/ajax-load-holidays',// use the `url` property
                   type: 'POST',
                   datatype: "JSON",
                   data : function()
                   { // a function that returns an object
                       var date =  new Date($('#calendar').fullCalendar('getDate'));
                       month_integer = date.getMonth();
                       year_integer = date.getFullYear();
                          return {
                              month: month_integer,
                              year: year_integer
                          }
                   },

                   error: function() {
                       alert('there was an error while fetching eventsin hol!');
                   },
                   color: 'yellow',   // a non-ajax option
                   textColor: 'blue' // a non-ajax option

               },


        ],
    eventRender: function(event, element, view) {
        // lets test if the event has a property called holiday.
        // If so and it matches '1', change the background of the correct day

        if (event.holiday == '1') {
            var dateString1 = event.start.format("YYYY-MM-DD");

            $(view.el[0]).find('.fc-day[data-date=' + dateString1 + ']')
                .css('background-color', '#FAA732','.fc-time','disable');
        }

    }

//这是我的控制器...我在 laravel(MVC-repository) 中做了这个

public function LoadHoliday(Request $request)
{



    $this->year = $request['year'];
    $month = $request['month'];


        $month++;
        $this->month=$month;

$Rowdata1 = ($this->holidayFixed->getValueMonth("monthOfTheYear",$this-month)); $Rowdata2 = $this->holidayMovable->getValueMonth("monthID",$this->month);

    $x=0;
    $data1[] = 0;
    $data2[] = 0;
    if($Rowdata1==null && $Rowdata2==null)
    {
        return 0;
    }
    else {


       foreach($Rowdata1 as $value){

            $mon = $value->monthOfTheYear;
            $day = $value->dayOfTheMonth;



            $dateD =  $this->year. '-' . $mon . '-' . $day;


            $data1[$x] = [
                'title' => $value->description,
                'start' => $dateD,
                'holiday' => '1'

            ];
           $x++;

        }

        foreach($Rowdata2 as $value){
            $year = ($value->yearID);
            $mon = $value->monthID;
            $day = ($value->dateID);

            $dateD = $year . '-' . $mon . '-' . $day;



            $data2[$x] = [
                'title' => $value->description,
                'start' => $dateD,
                'holiday' => '1'

            ];
            $x++;

        }
        if($data1==['0'] && $data2==['0'])
        {

          return 0;
        }
        elseif($data1==['0'])
        {

            return $data2;
        }
        elseif($data2==['0'])
        {

            return $data1;
        }
        else
        {
            unset($data2['0']);
            $data3 = array_merge($data1, $data2);

            return $data3;

        }


    }


}

于 2016-12-19T04:42:51.000 回答