When I define a controller action to display dates related to a specific date, it works correctly, but if I convert this controller action to a property, it stops displaying the date that occurs on a particular event. jsfiddle
App.EventsController = Em.ArrayController.extend({ todayEvent: function(date){ return this.get('content').filter(function(event) { return (moment(event.get('start')).unix() == moment(date).unix()); }); } });
I can get a controller instance:
u = App.__container__.lookup("controller:events")
in event 25, there are 2 events and I can get it using
u.todayEvent(new Date('2013-07-25').toString())
which correctly returns
[> Class, > class]
But in the CalendarEvent controller, I want to display events for a specific date exactly the same as above, but this time using computed-property, so I redefine the value of todayEvent asa as shown below, only this time, it returns true or false instead returning class objects associated with events for that day.
The date property is set using controllerFor in the serialization router, instead of passing it as we did when we defined todayEvent as the controller action earlier.
App.CalendarEventController = Em.ObjectController.extend({ date: null, needs: ['appointments'], todayEvent: function(){ var _self = this; var appoint = _self.get('controllers.appointments'); var appCont = appoint.get('content'); return appCont.map(function(appointee) { return (moment(appointee.get('event.start')).unix() == moment(_self.get('date')).unix()); }); }.property('date') });
Now I click the link for the appointment, then the link for the calendar and then select one of the dates in red from the calendar, so the serializer hook can set the controller date, after which I go to the console:
u = App.__container__.lookup("controller:calendarEvent")
try to retrieve events occurring on this date in the console using:
u.get('todayEvent')
I either get an empty array like this [] , or if I use map () instead of filter () , then it returns [false, false, false]
jsfiddle