Php 语法错误:缺少;在完整日历中显示事件时的before语句

Php 语法错误:缺少;在完整日历中显示事件时的before语句,php,jquery,ajax,fullcalendar,Php,Jquery,Ajax,Fullcalendar,我试图在我的项目中以完整的日历动态显示事件。有一个错误,我不知道这背后的原因是什么,但是当我硬编码事件数组时,它工作正常 日历Jquery代码: $(document).ready(function() { $('.fullcalendar').fullCalendar({ header: { left: 'prev,next today', center: 'title', right: 'mont

我试图在我的项目中以完整的日历动态显示事件。有一个错误,我不知道这背后的原因是什么,但是当我硬编码事件数组时,它工作正常

日历Jquery代码:

$(document).ready(function() {
    $('.fullcalendar').fullCalendar({
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,basicWeek,basicDay'
        },
        events: [
            eventList()
        ]
    });
Ajax调用

function eventList(){
    $.ajax({
        url :'/calendarMaintenanceData',
        type: 'GET',
        dataType: 'json',
        success:function(data){
            $.each(data, function (index, item) {                                                                                      
                {
                    id:item.id,
                    title:item.machinecode,
                    start:item.estimated_maintenance_date
                }
            }); 
        }
    });
}
错误:

$中。每个()
必须为这样定义的对象分配一个变量

$.each(data, function (index, item) {                                                                                      
                     var someobject =  {
                        id:item.id,
                        title:item.machinecode,
                        start:item.estimated_maintenance_date
                      };
                   }); 

eventList
需要将所有事件放入一个数组中。您可以使用
$.map
而不是
$。每个
都可以执行此操作

    success:function(data){
        return $.map(data, function (item) {  
            return {                                                                                    
                id:item.id,
                title:item.machinecode,
                start:item.estimated_maintenance_date
            };
        }); 
    }
然而,这仍然不会。问题是,
$.ajax
是异步的,因此回调函数的返回值不会返回到
fullcalendar
函数。创建数组后,需要在回调函数中调用
fullCalendar

function eventList(callback){
    $.ajax({
        url :'/calendarMaintenanceData',
        type: 'GET',
        dataType: 'json',
        success:function(data){
            callback($.map(data, function (item) {                                                                                      
                return {
                    id:item.id,
                    title:item.machinecode,
                    start:item.estimated_maintenance_date
                };
            }); 
        }
    });
}

$(document).ready(function() {
    eventList(function(events) {
        $('.fullcalendar').fullCalendar({
            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,basicWeek,basicDay'
            },
            events: events
        });
    });
});

我在这个新错误显示{TypeError:d未定义…form(d)),a.extend(i,d),e&&(i.source=e),i.。_id=d.。_id | |(void 0==d.id?_fc“+tb++:d…”之后分配变量您是否在某个地方定义了变量d,因为它不在您发布的代码中?否,我没有在任何地方使用变量d,我认为您需要在FullCalendar中的事件中将对象作为数组,但您的函数eventList()没有返回任何内容当我在类似这样的事件中使用函数时,此错误已被删除-events:function(){eventList();},