Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript fullCalendar-使用颜色选项添加EventSource_Javascript_Jquery_Calendar_Fullcalendar - Fatal编程技术网

Javascript fullCalendar-使用颜色选项添加EventSource

Javascript fullCalendar-使用颜色选项添加EventSource,javascript,jquery,calendar,fullcalendar,Javascript,Jquery,Calendar,Fullcalendar,我有一个功能,可以动态地将事件添加到日历中 function AddEventSourceDetailed(act_id) { $('#calendar').fullCalendar('addEventSource', function (start, end, callback) { var startTime = Math.round($('#calendar').fullCalendar('getView').start.getTime() / 1000);

我有一个功能,可以动态地将事件添加到日历中

function AddEventSourceDetailed(act_id) {
    $('#calendar').fullCalendar('addEventSource', function (start, end, callback) {
        var startTime = Math.round($('#calendar').fullCalendar('getView').start.getTime() / 1000);
        var endTime = Math.round($('#calendar').fullCalendar('getView').end.getTime() / 1000);
        time = endTime - startTime;
        //alert(time);
        if (time <= 604800) {
            $.ajax({
                type: 'POST',
                url: '/Employee/GetScheduleDetailedArray/',
                async: false,
                dataType: "json",
                data: {
                    // our hypothetical feed requires UNIX timestamps
                    start: Math.round(start.getTime() / 1000),
                    end: Math.round(end.getTime() / 1000),
                    id: '@Model.selectedUserId',
                    act: act_id
                },
                success: function (doc) {
                    callback(doc);
                },
                error: function (xhr, status, error) {
                    document.appendChild(xhr.responseText);
                }
            }); //end ajax
        } else {
            callback();
        }

    });
}
函数AddEventSourceDetailed(act\u id){
$(“#calendar”).fullCalendar('addEventSource',函数(开始、结束、回调){
var startTime=Math.round($('#calendar').fullCalendar('getView').start.getTime()/1000);
var endTime=Math.round($('#calendar').fullCalendar('getView').end.getTime()/1000);
时间=结束时间-开始时间;
//警报(时间);

如果(time在函数中,那么ajax调用的结果是什么?根据代码中的内容(成功:函数(doc){callback(doc);}),我猜如果成功,您将收到json编码的事件数组,因此添加颜色只需在服务器端脚本中为每个事件定义字段color、backgroundColor、borderColor、textColor。希望这对您有所帮助

一月

编辑:我还注意到您正在else分支中调用callback()函数,这是非常冗余的。如果没有参数,调用callback是毫无意义的,因为它什么都不做(callbacks参数是要添加到fullcalendar的事件数组,因此没有参数=没有要添加的事件=与它甚至没有被调用的事件相同)。

您可以使用:

$('#calendar').fullCalendar( 'addEventSource', {
    url: "/url/goes/here",
    color: '#05ABBD'
});

关于回调,你是对的()我更改了导入日历数据的方式,但忘记了将其取出。我在eventSources函数中使用了它,因此在测试时它不会破坏我的图表。我将尝试将参数添加到从serveside传入的json对象中。谢谢
$('#calendar').fullCalendar( 'addEventSource', {
    url: "/url/goes/here",
    color: '#05ABBD'
});