【发布时间】:2016-05-02 17:47:26
【问题描述】:
我正在使用 FullCalendar 在日历上显示员工时间。
我通过这样的 ajax 调用来拉事件:
"events": function(start, end, timezone, callback) {
//create the data to be sent
var objectToSend = {
"start_date": start.format("YYYY-MM-DD"),
"finish_date": end.format("YYYY-MM-DD"),
};
//craft and make the request
$.ajax({
url: 'calendar/test',
data: objectToSend,
type: 'POST',
cache: false
}).done(function(data) {
//on success call `callback` with the data
callback(data)
})
}
这工作得很好,但是我的控制台中显示一个错误“Uncaught TypeError: Cannot read property 'hasTime' of undefined”,这来自fullcalendar.min.js:6。
我的 JavaScript 不是很流利,但我的搜索表明我要么没有提供 right dates,要么没有提供 junk data。
据我所知,我提供了所有正确的数据。生成数据的函数如下所示:
public function test(Request $request) {
$start_date = Input::get('start_date');
$finish_date = Input::get('finish_date');
$shifts = Roster::whereBetween('date', array($start_date, $finish_date)) - > get();
foreach($shifts as $shift) {
$start = $shift - > date.
' '.$shift - > start_time;
$finish = $shift - > date.
' '.$shift - > finish_time;
$events[] = array(
'title' => $shift - > staff - > first_name,
'start' => Carbon::createFromFormat('Y-m-d H:i:s', $start) - > toDateTimeString(),
'end' => Carbon::createFromFormat('Y-m-d H:i:s', $finish) - > toDateTimeString(),
'id' => $shift - > id,
'allDay' => false
);
}
return json_encode($events);
}
哪个输出:
[{"title":"Gemma","start":"2016-02-01 18:00:00","end":"2016-02-01 22:00:00","id":1,"allDay":false},
{"title":"Gemma","start":"2016-01-26 18:00:00","end":"2016-01-26 22:00:00","id":49,"allDay":false}]
谁能发现我做错了什么?我只是想用它来呈现给定月份的事件。
编辑:console.log(data) 的输出
打印出来:
[Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object]
打开这个我得到:
0: Object
打开这个我得到:
allDay: false
end: "2016-02-01 22:00:00"
id: 1
start: "2016-02-01 18:00:00"
title: "Gemma"
【问题讨论】:
-
显示
callback函数.. -
@AndriyIvaneyko 我只是想关注这个fullcalendar.io/docs/event_data/events_function 不确定回调函数在哪里?除了以 XML 形式提供响应之外,我将其以 JSON 形式提供。
-
好的,尝试将
callback(data)替换为callback(data[0]) -
能否在
done函数中调用回调之前提供console.log(data) -
@AndriyIvaneyko 刚刚尝试过,我得到了同样的错误。
标签: javascript jquery laravel fullcalendar laravel-5.1