在月视图中,我单击日期,然后视图将更改为日视图。当我点击新的活动链接时,我希望开始日期是所选日期的日期,而不是今天日期的默认日期。
如果今天是2013年3月12日,并且我想在2013年3月28日创建一个活动,我将在月视图中点击3月28日的日期单元格。 3月28日的日视图将会出现。我将点击新活动,活动的开始时间将是2013年3月12日(无论当天是什么日期),我需要手动选择2013年3月28日(或我想要的任何一天)。 / p>
我想出了硬编码的方法,但这不会在生产中发挥作用。有没有办法动态传递选定日期的开始日期,以便选择自动设置为月中的任何一天?
这是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?
如何通过dayClick传入所选日期的参数?或者我从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).
答案 0 :(得分:0)
我不确定这是否是最好的解决方案,但这就是我如何使用它。在events.js.coffee中:
$('#calendar').fullCalendar
dayClick: (date, allDay, jsEvent, view) ->
if (allDay)
# clicked entire day
$('#calendar')
.fullCalendar('changeView', 'agendaDay')
.fullCalendar('gotoDate', date.getFullYear(), date.getMonth(), date.getDate())
$('#new-event').append("<a>custom link built thru js</a>").attr( 'href', 'events/new?starts_at=' + date )