fullcalendar-eventclick更改网址 [英] fullcalendar - eventclick changing URL

查看:114
本文介绍了fullcalendar-eventclick更改网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在eventClick中更改事件的URL?我更改了它,但是当我在日历上使用updateEvent时,它并没有接受我的更改,它具有原始值.

How can I change the event's URL in the eventClick? I change it but when I updateEvent on the calendar it doesn't take my change it has the original value.

var path = window.location.origin + window.location.pathname + calEvent.url;
calEvent.url = path;
//update the calEvent
$('#calendar').fullCalendar('updateEvent', calEvent);

推荐答案

在eventClick运行时为时已晚,您已经单击了该事件,并且已经开始重定向到现有事件URL中指定的位置.

By the time eventClick runs it's too late, you already clicked on the event and the redirection to the location specified in the existing event URL has already started.

如果您想操纵来自服务器的URL值,我建议您在eventDataTransform回调中执行此操作,该回调在每个事件呈现到日历之前运行,例如:

If you want to manipulate the URL values coming from the server I suggest you do this in the eventDataTransform callback, which runs before each event is rendered onto the calendar, e.g.:

eventDataTransform: function( eventData ) {
    eventData.url = window.location.origin + window.location.pathname + eventData.url;
    return eventData;
},

请参阅 https://fullcalendar.io/docs/event_data/eventDataTransform/有关回调的更多信息.

See https://fullcalendar.io/docs/event_data/eventDataTransform/ for a bit more detail on the callback.

但是,我不知道您的URL确切是哪种格式,但是我认为您的代码实际上是不必要的.我认为为了使其有意义,您必须将相对URL输出到日历数据中,例如"test.php"或"images/test.jpg".

However, I don't know exactly what format your URLs are in but I sense that your code is actually unnecessary. I think for it to make sense you must be outputting relative URLs into the calendar data e.g. "test.php" or "images/test.jpg".

如果您将其保留不变并单击它们,浏览器将在尝试导航到它们之前自动将当前站点地址添加到它们之前.您正在运行的代码只是硬编码浏览器将自动执行的操作,我认为您不必费心.

If you leave these as they are and click on them, the browser will automatically prepend the current site address onto them before trying to navigate there. The code you're running just hard-codes what the browser will do automatically, and I don't think you need to bother.

这篇关于fullcalendar-eventclick更改网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆