Search code examples
javascriptember.jschartsember-data

Work with data before return it in Ember.js


I'm trying to build a chart using Google Chart in Ember.js but I'don't know how to deal with data in the route/controller before returning the data to the view...

Indeed I need to transform my object into an array for Google Chart.

Is it even possible to do that with Ember.js ?

import Ember from 'ember';

export default Ember.Route.extend({
    model() {
        this.store.findAll('rate').then(data => {
            console.log(data);
        });
        return [
            ['Task', 'Hours per Day'],
            ['Work', 11],
            ['Eat', 2],
            ['Commute', 2],
            ['Watch TV', 2],
            ['Sleep', 7],
        ];
    }
});

I want to return data from my rate store instead of hard coded values.


Solution

  • Yes.Its possible you can iterate your result construct the required format and return it.

     model() {
            return this.store.findAll('rate').then(data => {
                //do all kinds of transformation and dont forget to return.
                return data;
            })
        }