mercredi 22 février 2017

Ember order list alphabetically

I want to order the output of Extensions by name. My template includes the code below to list all extensions:

      
        
      

And my controller defines Extensions as follows:

      extensions: Ember.computed('model.stats', function() {
        let selectedExtensions = this.get('selectedExtensions');
        if (!this.get('model.stats.extensions')) { return []; }
        return this.get('model.stats.extensions').map(extension => {
          let flag = selectedExtensions.length === 0 || selectedExtensions.includes(extension);
          return new Ember.Object({value: extension, selected: flag});
        });
      }),

  setDefaultFilters: Ember.observer('model.stats', function() {
    if (this.get('selectedExtensions').length === 0 && this.get('model.stats.extensions')) {
      this.set('selectedExtensions', this.get('model.stats.extensions'));
    }

    if (this.get('selectedCountries').length === 0 && this.get('model.stats.countries')) {
      this.set('selectedCountries', this.get('model.stats.countries'));
    }

    if (this.get('selectedLangauges').length === 0 && this.get('model.stats.languages')) {
      this.set('selectedLangauges', this.get('model.stats.languages'));
    }
  }),

But the output is not ordered alphabetically. How do I order the output in such a way?




Aucun commentaire:

Enregistrer un commentaire