vendredi 4 septembre 2015

Ember.js 2.0 Struggling to make hardcoded list available in template

I am currently building an application where a User will have to correct data within a prefilled form.

This form we will have some <select> that can show a selected value that corresponds to the data sent by the server. And sometimes we will not have data corresponding to that select, so we will not preselect any data. The server with never send me the list of all the possible values so I have to hard code then somewhere.

For that, I thought about creating an enumerable in the Route, for each list, and expose those to the Template via the setupController method.

1st question: is this a good way of doing?

2nd question: the code below is what I wrote and it does not work. When I call {{buildingDescriptions.length}} in the template, it does not show anything whereas the console outputs the right value... Also the {{each-in}} loop does not work either.

import Ember from 'ember';

const { computed, RSVP } = Ember;

export default Ember.Route.extend({

  buildingDescriptions: computed(function() {
    const descriptions = Ember.A([
      {value: 'oneFamilyHouse', desc: ''},
      {value: 'oneFamilyHouseWithSmallFlat', desc: ''},
      {value: 'twoFamilyHouse', desc: ''},
      {value: 'twoFamilyHouseWithSmallFlat', desc: ''},
      {value: 'threeFamilyHouse', desc: ''},
      {value: 'garageOrShelter', desc: ''}
    ]);

    return RSVP.hash({descriptions: descriptions}).then(
      function(results) {
        Ember.Logger.log(results.descriptions.length);
        Ember.Logger.log(results.descriptions);
        return results.descriptions;
      }
    );
  }),

  model() {

  },

  setupController(controller) {
    Ember.Logger.log(this.get('buildingDescriptions'));
    controller.set('buildingDescriptions', this.get('buildingDescriptions'));
  }
});

Many thanks in advance. Cheers




Aucun commentaire:

Enregistrer un commentaire