【发布时间】:2020-06-16 05:58:25
【问题描述】:
只有当我在 EventController 中对事件进行硬编码时,我的事件提要才有效。一旦我从数据库查询中获取它们,尽管第一个事件与我在硬编码事件中使用的完全相同,但不会显示事件。
作品(日历显示事件):
public function eventFeed(Request $request)
{
$events = array(
[
"id" => 1,
"resourceId" => '1115',
"title" => 'Wartung Steuerung',
"start" => '2020-06-11 00:20:23',
"end" => '2020-06-28 21:21:30',
]
);
return json_encode($events);
}
从日历视图中,我有一个控制 Ajax 调用,它获取与 FullCalendar 相同的提要。收到的提要是
[{"id":1,"resourceId":"1115","title":"Wartung Steuerung","start":"2020-06-11 00:20:23","end":"2020-06-28 21:21:30"}]
不起作用(日历保持空白):
public function eventFeed(Request $request)
{
$start = Carbon::create($request->input('start'));
$end = Carbon::create($request->input('end'));
$events = DB::table('toolplanview')->select('id','resourceId','title','start','end')
->whereDate('start', '>=', $start)->whereDate('end', '<=', $end)->get();
return json_encode($events);
}
来自数据库查询的提要是:
[{"id":1,"resourceId":"1115","title":"Wartung Steuerung","start":"2020-06-11 00:20:23","end":"2020-06-28 21:21:30"},{"id":2,"resourceId":"1157","title":"Werkstatt","start":"2020-06-12 09:09:41","end":"2020-06-24 03:45:59"},{"id":3,"resourceId":"1136","title":"Neue Toranlage","start":"2020-06-10 20:29:44","end":"2020-06-23 04:26:38"},{"id":4,"resourceId":"1138","title":"Neue Toranlage","start":"2020-06-10 03:23:12","end":"2020-06-28 11:20:36"}]
我不明白为什么这个提要不起作用。我的日历:
document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
schedulerLicenseKey: 'GPL-My-Project-Is-Open-Source',
locale: 'de',
plugins: [ 'interaction', 'resourceTimeline' ],
defaultView: 'resourceTimelineWeek',
editable: true,
titleFormat: { year: 'numeric', month: '2-digit', day: '2-digit' },
header: {
right: 'today prev,next'
},
slotLabelFormat: [
{ month: 'long', year: 'numeric' }, // top level of text
{ weekday: 'short', day: '2-digit' } // lower level of text
],
resources: 'http://localhost/matpro/public/resource-feed',
events: 'http://localhost/matpro/public/event-feed',
});
calendar.render();
});
【问题讨论】:
-
我唯一看到的错误是您定义了
RESOURCE_URL和FEED_URL,但从不使用它们;你有resources: 'http://localhost/matpro/public/resource-feed',和events: 'http://localhost/matpro/public/event-feed',硬编码。 -
那来自测试。我现在从列表中删除了它们。
-
不用担心。通常,Laravel URL 中没有
/public,但如果它使用从 URL 返回的硬编码值,那么我怀疑这是一个问题。您的控制台中是否有任何错误?F12或CMD + SHIFT + I(或 Windows 上的CTRL),然后是控制台。或者检查您的网络选项卡中的/event-feed请求,看看返回了什么。 -
控制台或 Laravel 日志没有错误。网络使用“/event-feed”和正确的“start”和“end”参数显示正确的请求。这就是为什么我使用 Ajax 调用来控制 Json。我在请求或返回中看不到错误。
-
我会用“有趣的”来换取“快速的解决方案”;P 已经在这上面浪费了一整天,如果这里没有出现任何问题,最好将其作为问题报告给 Github 官方网站。
标签: json laravel fullcalendar-4