2013-03-12 152 views
1

在月視圖中,我單擊日期,然後視圖更改爲日視圖。當我點擊新的活動鏈接時,我希望開始日期是選定日期而不是今天的默認日期。如何通過函數將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). 

回答

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) 
+0

你有這個小提琴嗎? – Peege151 2014-10-18 13:57:57

相關問題