HTML in title string of fullcalendar jquery plugin

前端 未结 6 1921
离开以前
离开以前 2021-01-31 08:18

I think the fullcalendar jquery-plugin is a really great solution. However, I noticed the plugin escapes (htmlEscape) the title. But I need to format some strings in the title,

6条回答
  •  北恋
    北恋 (楼主)
    2021-01-31 08:59

    I ended up doing something like this to put a link next to the time. Something similar should work for the title:

        events: [
          <% @schedule.events.each do |event| %>
          {
            // Render your events here as needed
            // I added a custom attribute called eventDeleteLink, to be used below
          },
          <% end %>
        ],
        // Add this piece:
        eventRender: function(event, element) {
          element.find(".fc-event-time").append(" " + event.eventDeleteLink);
        }
    

    So this uses jQuery's append() to add a space any a delete link after the time and it works fine for basic stuff.

    What it didn't work for (and what I'd love to see a solution for, if anyone has one) is including code with nested quotes or double quotes. For instance, I was unable to add an onClick trigger because of the need (in my case) for single quotes within double quotes. I couldn't figure out how to escape them and not have (what I believe is) fullCalendar re-escaping them.

    Anyway, for basic text, this worked for me.

提交回复
热议问题