jeudi 14 avril 2016

Ember data model setter

What is the most simple way to override setter for DS.Model. I have

month: DS.attr('date'),    
monthSetter: function() {
   const rawDate = this.get('month');
   if (rawDate) {
       var start = new Date(rawDate.getFullYear(), rawDate.getMonth(), 1);
       this.set('month', start);
   }
}.observes('month'),

and, of course, it gives an infinite loop. I need month property to be always beginning of month.

Aucun commentaire:

Enregistrer un commentaire