lundi 15 janvier 2018

Calling Ember Model in Computed Property returns incorrect array

I'm trying to format data held in an Ember Model so that I can plug it into a Chart Component.

Route code:

import Route from '@ember/routing/route';
export default Route.extend({
  model() {
      let dateFrom = this.paramsFor('dashboard').dateFrom
      let dateTo = this.paramsFor('dashboard').dateTo
      let hash = {dateFrom, dateTo}
  return Ember.RSVP.hash({
    custakelist: this.get('store').query('custakelist', hash),
    barchart: this.get('store').query('barchart', hash),
      });
},

setupController(controller, models) {
  this._super(controller, models);
  controller.set('barchart', models.barchart);
  controller.set('custakelist', models.custakelist);
},

Controller Code:

import Controller from '@ember/controller';
import groupBy from 'ember-group-by';
export default Controller.extend({
  entriesByDate: groupBy('custakelist', 'take_list_date'),
  entriesByAge: groupBy('custakelist', 'patient_age'),

  wardData: Ember.computed.map('entriesByDate', function(group) {
      return {
      label: group.value,
      count: group.items.length
    };
  }),

  ageData: Ember.computed.map('entriesByAge', function(group) {
      return {
      label: group.value,
      count: group.items.length
    };
  }),

  clerkData: Ember.computed.map('barchart', function(barchart) {
      return {
      label: barchart.label,
      count: barchart.count
    };
  }),

});

I know that the models are being loaded on the page correctly thanks to Ember Data. I also know that the 'custakelist' model is being used by other charts.

When I try to use the model 'barchart' and log the result to the console I can see that an array with the correct number of items is created but they don't contain any values, they just display as follows:

0: {label: Computed Property, count: Computed Property}

How can I make the data that is already loaded as per my model usable in this context?




Aucun commentaire:

Enregistrer un commentaire