Displaying image inside a fullcalendar event with eventRender

拥有回忆 提交于 2019-12-06 12:28:06

问题


I am trying to display an image in the fc-event-inner class using addClass. I want to do this with jquery so I can use different images in different events. Can anyone tell me why this doesn't work?

calendar.fullCalendar('renderEvent', {
    title: title,
    start: start,
    end: end,
    allDay: allDay,
    eventRender: function(copiedEventObject,element) {                                          
        element.find('.fc-event-inner').css('background-image',"url(icons/kalender_medicin_100px.png)")
    },
    className: '.fc-event-inner'
});

回答1:


You should specify the eventRender in the fullCalendar configuration, not pass it through the renderEvent method.

$('#calendar').fullCalendar({
    eventRender: function(copiedEventObject,element) {
        var icon = $(document.createElement('div'));
        icon.css('background-image',"url(icons/kalender_medicin_100px.png)");
        element.find('.fc-event-title').html(icon + copiedEventObject.title);
    }
});

If you want to add icons only to the dragged events you can pass an custom property to the event data like so:

calendar.fullCalendar('renderEvent', {
    //...
    isCustom: true,
    //...
}

Now you can check if the event has the custom property in the eventRender event.

eventRender: function(copiedEventObject,element) {
    if(copiedEventObject.isCustom){
    //...
}



回答2:


Thanks for the help. It helped me solve the problem.

But this code only returned an object and did'nt display the image:

    var icon = $(document.createElement('div'));
    icon.css('background-image',"url(icons/kalender_medicin_100px.png)");
    element.find('.fc-event-title').html(icon + copiedEventObject.title);

So insted of using:

   icon.css('background-image',"url(icons/kalender_medicin_100px.png)");

I placed the image in the fc-event-title div. So the solution is this:

    element.find('.fc-event-title').html('<p>Ingen migræne idag</p><img src="icons/kalender_glad_smiley.png"/>');

The only problem is that I can't use variables inside the html method, but in this context its not a problem. Thanks again



来源:https://stackoverflow.com/questions/21327886/displaying-image-inside-a-fullcalendar-event-with-eventrender

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