Emberjs-1.0.0-rc.6 using an enumerated list of events occurring on a specific date

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

0
source share
1 answer

Looks like you need to add 'content. @each 'to your computed property.

As of now, "todayEvent" will be calculated only when the date changes. I assume the date is set to or at the same time as the content.

todayEvent returns [false, false] because you are using a non-filter map.

 todayEvent: function(){ var _self = this; var appoint = _self.get('controllers.appointments'); var appCont = appoint.get('content'); return appCont.filter(function(appointee) { return (moment(appointee.get('event.start')).unix() == moment(_self.get('date')).unix()); }); }.property(' content.@each ', 'date') 
+1
source

Source: https://habr.com/ru/post/1242044/


All Articles