mercredi 11 avril 2018

Ember: filter not working

Component is working, the data is getting rendered just fine. Here it is:

import Component from '@ember/component';

export default Component.extend({
  classNames: ['list-filter'],
  value: '',

  init() {
    this._super(...arguments);
    this.get('filter')('').then((allResults) => this.set('results', allResults.results));
  },

  actions: {
    handleFilterEntry(val) {
      let filterInputValue = this.get('value');
      let filterAction = this.get('filter');
      filterAction(filterInputValue).then((resultsObj) => {
        if (resultsObj.query === this.get('value')) {
          this.set('results', resultsObj.results);
        }
      });
    }
  }
});

This is controller:

import Controller from '@ember/controller';

export default Controller.extend({
    actions: {
        filterByName: function (param) {
            if (param !== '') {
                return this.get('store').query('rental', { name: param }).then((filteredResults) => {
                    return { query: param, results: filteredResults };
                });
            } else {
                return this.get('store').findAll('rental').then((results) => {
                    return { query: param, results: results };
                });
            }
        }
    }
});

What happens is that whenever I enter the data in the filter, it keeps getting the whole list of rentals, not part I want. handleFilterEntry is getting called. What am I doing wrong? Please let me know if additional info needed.




Aucun commentaire:

Enregistrer un commentaire