Restructure data before output in template


#1

Guys, i’m using this ember-full-calendar add-on and i need re-structure my data because in the currently format full calendar can’t read it.

I’m doing this:

First i’m returning all my events in the route:

export default Route.extend({
  model() {
    return this.store.findAll('event');
  }
});

After, i’m using my controller to adapt my events:

  events: [],

  eventsObs: observer('model', function() {
    let events = [];

    this.get('model').forEach((item) => {
      events.pushObject({
        id    : item.id,
        title : item.get('title'),
        start : item.get('start'),
        end   : item.get('end')
      })
    });

    this.set('events', events);
  })

And finally i can call full-calendar component:

{{full-calendar events=events lang="pt-br"}}

I have the impression that the Ember can help me better. Could you give me a hand , maybe some tips?

Thank you!


#2

you don’t need the controller part, for your model:

export default Route.extend({
  model() {
    return this.store.findAll('event')
      .then(events => events.map(event => {
        return {
          id: event.get('id'),
          title: event.get('title'),
          start: event.get('start'),
          end: event.get('end')
        }
      }))
  }
}

#3

Lol… i knew it! hahaha. Thanks nightire!