mardi 3 novembre 2015

State changes after Ember.computed finished

I have an Ember app that displays a list of borrowed articles in a table. One table cell has a select helper that has either 'borrowed' or 'returned' as value.

I also have a checkbox that triggers the showing of returned items via query Parameters.

When I set my checkbox to not show returned items and set one item from 'borrowed' to 'returned', the article will stay visible.

So what I will have to do is reload the 'filteredResults' with the state change incorporated.

I read about Ember.observer but I'm not sure it's the right thing to use for this.

import Ember from 'ember';

export default Ember.Controller.extend({
  queryParams: ['showReturned'],
  showReturned: false,
  possibleStates: ['borrowed', 'returned'],
  filteredResults: Ember.computed('showReturned', 'model', function() {
    const articles = this.get('model');
    if (this.get('showReturned')) {
      return articles;
    } else {
      return articles.filterBy('state', 'borrowed');
    }
  })
});




Aucun commentaire:

Enregistrer un commentaire