fullcalendar - eventclick changing URL

≡放荡痞女 提交于 2020-05-30 05:17:41

问题


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);

回答1:


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.

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;
},

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


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.



来源:https://stackoverflow.com/questions/48932252/fullcalendar-eventclick-changing-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!