3

ここにnoobコーダーがあります。バックボーンコレクションからfullcalendarイベントを読み込むと、次の機能と前の機能が中断されます

fullcalendarをbackbone.jsにリンクする際に問題があります。私の問題は、fullcalendarの 'previous'と 'next'ボタンを使って移動するときに発生します。

ここはバグです:私は新しいイベントを作ります。イベントはカレンダーに表示されます。私は '次へ'を押す。私は '前'を押す。新しい出来事は消えた。

fullcalendarは、イベントをロードする関数またはJSONフィードを指定するために読み込み時に 'events'オプションが必要になるようです。ドキュメントによると、「FullCalendarは、新しいイベントデータが必要なときはいつでもURLにアクセスします。これは、ユーザーがprev/nextをクリックするかビューを変更したときに発生します。

Fullcalendarを取得して、すべてのイベントを格納するイベントコレクションのJSONオブジェクトをBackboneに問い合わせるのは驚くほど困難です。

Iは イベント用いて試みた:関数(){events.toJSON();} とイベント:関数(){events.fetch();}運と 。ヘルプは非常に感謝しています。ここで

は私のバックボーンコードです:

$(function(){ 
    var Event = Backbone.Model.extend(); 

    var Events = Backbone.Collection.extend({ 
     model: Event, 
     url: 'events' 
    }); 

    var EventsView = Backbone.View.extend({ 
     initialize: function(){ 
      _.bindAll(this); 

      this.collection.bind('reset', this.addAll); 
      this.collection.bind('add', this.addOne); 
      this.collection.bind('change', this.change);    
      this.collection.bind('destroy', this.destroy); 

      this.eventView = new EventView();    
     }, 
     render: function() { 
      this.el.fullCalendar({ 
       header: { 
        left: 'prev,next today', 
        center: 'title', 
        right: 'month,basicWeek,basicDay' 
       }, 
       selectable: true, 
       selectHelper: true, 
       editable: true, 
       ignoreTimezone: false,     
       select: this.select, 
       defaultView: 'agendaWeek', 
      // events: function() {events.toJSON();}, 
       eventClick: this.eventClick, 
       eventDrop: this.eventDropOrResize,   
       eventResize: this.eventDropOrResize 
      }); 
     }, 
     addAll: function() { 
      this.el.fullCalendar('addEventSource', this.collection.toJSON()); 
     }, 
     addOne: function(event) { 
      this.el.fullCalendar('renderEvent', event.toJSON()); 
     },   
     select: function(startDate, endDate) { 
      this.eventView.collection = this.collection; 
      this.eventView.model = new Event({start: startDate, end: endDate}); 
      this.eventView.render();    
     }, 
     eventClick: function(fcEvent) { 
      this.eventView.model = this.collection.get(fcEvent.id); 
      this.eventView.render(); 
     }, 
     change: function(event) { 
      // Look up the underlying event in the calendar and update its details from the model 
      var fcEvent = this.el.fullCalendar('clientEvents', event.get('id'))[0]; 
      fcEvent.title = event.get('title'); 
      fcEvent.color = event.get('color'); 
      this.el.fullCalendar('updateEvent', fcEvent);   
     }, 
     eventDropOrResize: function(fcEvent) { 
      // Lookup the model that has the ID of the event and update its attributes 
      this.collection.get(fcEvent.id).save({start: fcEvent.start, end: fcEvent.end});    
     }, 
     destroy: function(event) { 
      this.el.fullCalendar('removeEvents', event.id);   
     }   
    }); 

    var EventView = Backbone.View.extend({ 
     el: $('#eventDialog'), 
     initialize: function() { 
      _.bindAll(this);   
     }, 
     render: function() { 
      var buttons = {'Ok': this.save}; 
      if (!this.model.isNew()) { 
       _.extend(buttons, {'Delete': this.destroy}); 
      } 
      _.extend(buttons, {'Cancel': this.close});    

      this.el.dialog({ 
       modal: true, 
       title: (this.model.isNew() ? 'New' : 'Edit') + ' Event', 
       buttons: buttons, 
       open: this.open 
      }); 

      return this; 
     },   
     open: function() { 
      this.$('#title').val(this.model.get('title')); 
      this.$('#color').val(this.model.get('color'));    
     },   
     save: function() { 
      this.model.set({'title': this.$('#title').val(), 'color': this.$('#color').val()}); 

      if (this.model.isNew()) { 
       this.collection.create(this.model, {success: this.close}); 
      } else { 
       this.model.save({}, {success: this.close}); 
      } 
     }, 
     close: function() { 
      this.el.dialog('close'); 
     }, 
     destroy: function() { 
      this.model.destroy({success: this.close}); 
     }   
    }); 

    var events = new Events(); 
    new EventsView({el: $("#calendar"), collection: events}).render(); 
    events.fetch(); 
}); 

答えて

0

この問題を見た後に永遠に私は私がコレクションに任命(モデル)を追加すると、同じ[、スティック]フラグなしrenderEvent()を呼んでいたことに気づきました本当に。これにより、次/戻るボタンを押したときに予定が消えました。ドキュメントから

http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/

: "http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/"

「は通常、イベントはカレンダーいったん消えますが、そのイベントソースを(再フェッチexample:prev/nextがクリックされたとき)。ただし、stickをtrueに指定すると、イベントはカレンダーに永続的に固定されます。

関連する問題