在月视图中,我单击日期,然后视图更改为日视图。当我点击新的活动链接时,我希望开始日期是选定日期而不是今天的默认日期。如何通过函数将fullcalendar动态传递给新事件?
如果今天是2013年3月12日,并且我想在2013年3月28日创建活动,我将在月视图中点击3月28日的日期单元格。 3月28日的日子将会出现。我将点击新的活动,并且活动的开始时间将为2013年3月12日(显示当天),我需要手动选择2013年3月28日(或任何我想要的日期)。
我想出了硬编码的方法,但这不适用于生产。有没有办法动态地通过选定日期的开始日期,以便它自动设置为每月的任何一天被选中?
这里的dayClick代码:
dayClick: (date, allDay, jsEvent, view) ->
if (allDay)
# clicked entire day
$('#calendar')
.fullCalendar('changeView', 'agendaDay')
.fullCalendar('gotoDate', date.getFullYear(), date.getMonth(), date.getDate())
我用select方法?如果是的话如何?我不明白的文档http://arshaw.com/fullcalendar/docs/selection/select_method/ http://arshaw.com/fullcalendar/docs/selection/select_callback/
在events.js.coffee,我试图动态创建的一个新的事件链接:
$('#new-event').append("<a>custom link built thru js</a>").attr('href', 'events/new?starts_at=2013-03-28') <-- How to set starts_at by obtaining the date from day selected dynamically? Use calendar's select method to obtain the date parameters?
是怎样的参数选定从日期的日期点击传入?或者我从gotoDate获取这些信息?
EventsController.rb:
# GET /events/new
# GET /events/new.json
def new
@event = Event.new
@event.starts_at = (params[:starts_at]) # sets the date
respond_to do |format|
format.html # new.html.erb
format.json { render :json => @event }
end
end
Event.rb型号:
def as_json(options = {})
{
:id => self.id,
:title => self.title,
:description => self.description || "",
:start => starts_at,
:end => ends_at,
:allDay => self.all_day,
:recurring => false,
:url => Rails.application.routes.url_helpers.event_path(id),
:type_of => self.type_of
}
end
的意见/日历/ show.html.erb:
<%= link_to "new event", controller: "events",
action: "new",
starts_at: "28-03-2013" %> This will set the starts_at param manually via Rails. How do I obtain this dynamically? Using jQuery see code above in to create link that has the starts_at parameter (see code above).
你有这个小提琴吗? – Peege151 2014-10-18 13:57:57