In this jsfiddle, inside the didInsertElement hook, I am trying to call a controller method called eventJSON, which is defined in CalendarsController, I am storing or passing that call to the controller action in a variable called calendarJSON that i declared inside the didInsertElement hook in the CalendarsView. But when I log the result, it gives undefined. Also if I put a debugger inside the didInsertElement hook and inspect the variable in the console, it returns undefined.
I want to store the data returned from var calendarJSON = this.get('controller').send('eventJSON'); in variable because I want to subsequently passed that data to fullcalendar jquery.
The jsfiddle
The controller:
App.CalendarsController = Em.ArrayController.extend({
eventJSON: function() {
//returns the json of controller's content
this.invoke('toJSON');
return this.get('content');
}
});
The view:
App.CalendarsView = Ember.View.extend({
templateName: 'calendars',
attributeBindings: ['id'],
id: "mycalendar",
didInsertElement: function() {
debugger;
this._super();
//Right here is the problem
var calendarJSON = this.get('controller').send('eventJSON');
console.log(calendarJSON);
this.$().fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: true,
events: calendarJSON
});
}
});