sendAction from component with fullcalendar


#1

why this sendAction does not call addEvent in controller?

I get in console: Uncaught TypeError: undefined is not a function

So obviously “this” is pointing somewhere else, how to call sendAction then?

Bellow is component code:

import Ember from ‘ember’;

export default Ember.Component.extend({

newEvent: “”, eventTitle: “”,

_initializeCalendar: (function() {

return $("#calendar").fullCalendar({

  header: {

			left: 'prev,next today',

			center: 'title',

			right: 'month,agendaWeek,agendaDay'
		},

		defaultDate: Date.now(),

		editable: true,

		eventLimit: true, // allow "more" link when too many events

  events: this.theEvents,

  dayClick: function(date, jsEvent, view) {

      this.sendAction("addEvent")

  }

});

}).on(“didInsertElement”)

});


#2

You have a “scoping” problem as this within your dayClick() function doesn’t refer to your Ember.Component but instead to the dayClick() function itself.

You’d need to create a var self = this; outside of the dayClick() function or use .bind(this) on the function body in order to get things to work. :smiley:

(but such questions are better suited over at stackoverflow.com)


#3

that was lightning fast response :slight_smile: thanks,

It was my first posting, what type of questions are better for this forum and what for stackoverflow? Are ember topics on stackoverflow also looked by experienced Ember people?

Thanks