FullCalendar语言 - 添加多个事件或添加事件源



我已经看过stackoverflow的帖子,将事件添加到FullCalendar中,但是我真的很新,发现没有例子很难理解。简而言之,有人能帮我简化一下,以便在FullCalendar中添加一个对象数组吗?

我想添加我已经创建的约会约会(日期日期,字符串名称,字符串phoneNo)。所以它们在list:

中检索
 PersistenceManager pm = PMF.get().getPersistenceManager();
 String query = "select from " + Appointment.class.getName();  
 query += " where merchant == '" + session.getAttribute("merchant") + "'";
 List<Appointment> appointment = (List<Appointment>) pm.newQuery(query).execute();

我如何能够填充FullCalendar插件与我获得的列表?非常感谢!

如果有人遇到与我相同的问题—您有一个java对象列表,并希望它填充FullCalendar,那么解决方案如下:

JSP页面

$(document).ready(function() {
            var calendar = $('#calendar').fullCalendar({
                header: {
                    left: 'prev,next today',
                    center: 'title',
                    right: 'month,agendaWeek,agendaDay'
                        },
                    selectable: true,
                    selectHelper: true,
                select: function(start, end, allDay) {
                        var title = prompt('Event Title:');
                        if (title) {
                            calendar.fullCalendar('renderEvent',
                            {
                                title: title,
                                start: start,
                                end: end,
                                allDay: allDay
                            },
                            true // make the event "stick"
                            );
                            }
                            calendar.fullCalendar('unselect');
                        },
                                editable: true,
                                eventSources: [
                                    {
                                            url: '/calendarDetails',
                                            type: 'GET',
                                            data: {
                                                start: 'start',
                                                end: 'end',
                                                id: 'id',
                                                title: 'title',
                                                allDay: 'allDay'
                                            },
                                            error: function () {
                                                alert('there was an error while fetching events!');
                                            }
                                    }
                            ]         
                    });
            });

请不要拿走URL,它是servlet URL

Servlet

    public class CalendarServlet extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
                throws IOException {
        String something = req.getSession().getAttribute("merchant").toString(); //get info from your page (e.g. name) to search in query for database
        //Get the entire list of appointments available for specific merchant from database
        //Convert appointment to FullCalendar (A class I created to facilitate the JSON)
        List<FullCalendar> fullCalendar = new ArrayList<FullCalendar>();
        for (Appointment a : appointment) {
            String startDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(a.getDate());
            startDate = startDate.replace(" ", "T");
            //Calculate End Time
            Calendar c = Calendar.getInstance();
            c.setTime(a.getDate());
            c.add(Calendar.MINUTE, 60);
            String endDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(c.getTime());
            endDate = endDate.replace(" ", "T");
            FullCalendar fc = new FullCalendar(startDate, endDate, a.getId(), a.getName() + " @ " + a.getPhone(), false);
            fullCalendar.add(fc);
        }
        //Convert FullCalendar from Java to JSON
        Gson gson = new Gson();
        String jsonAppointment = gson.toJson(fullCalendar);
        //Printout the JSON
        resp.setContentType("application/json");
        resp.setCharacterEncoding("UTF-8");
        try {
            resp.getWriter().write(jsonAppointment);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

如果您需要更多关于JSON或GSON的信息,请查看上面的评论

Melvin你在Stack中有很多例子,试着搜索add event sources

根据我在fullcalendar的经验,您可以通过JSON,格式良好的XML和数组添加事件,我认为就是这样。你可以使用ajax调用来检索3种格式。

在你的服务器端,你应该创建一个方法来返回一个字符串已经与XML/JSON/数组构建,所以你可以传递给你的ajax调用。

查看https://github.com/mzararagoza/rails-fullcalendar-icecube这是在rails中完成的但我认为你要找的是

dayClick: function(date, allDay, jsEvent, view) {
          document.location.href=new_event_link + "?start_date=" + date;
},
jquery完整

$('#calendar').fullCalendar({
        dayClick: function(date, allDay, jsEvent, view) {
          document.location.href=new_event_link + "?start_date=" + date;
        },
          header: {
              left: 'prev,today,next',
              center: 'title',
              right: 'month,agendaWeek,agendaDay'
          },
          selectable: true,
          selectHelper: true,
          editable: false,
          ignoreTimezone: false,
          select: this.select,
          eventClick: this.eventClick,
          eventDrop: this.eventDropOrResize,
          eventSources: [
            {
                url: '/event_instances.json',
                data: {
                    custom_param1: 'something',
                    custom_param2: 'somethingelse'
                },
                error: function() {
                    alert('there was an error while fetching events!');
                }
            }
          ],
          eventResize: this.eventDropOrResize
      });

相关内容

  • 没有找到相关文章

最新更新