mercredi 5 juillet 2017

ember filter on promised inside a model

i have two models: User:

export default DS.Model.extend({
  books: hasMany('book', { async: true }),
});

book:

export default DS.Model.extend({
  title: DS.attr('string'),
  state: DS.attr('number'),
});

in my of my controller i am getting one user as my model and i want to create a computed property like this

  activeBooks: Ember.computed('model.books', function() {
    var books = this.get('model.books').filter(function (book, index, array) {
      // debugger;
      return (this.get('book.state') === 1);
    }.bind(this));
    return books;
  }),

but the filter is not working and basically return a empty array. P.S 1. i am side loading books alone with user. and at the debugger line i query for this.get('user.books.length') i get the correct number of books for each user. could someone point out what i am doing wrong here? thanks a lot!




Aucun commentaire:

Enregistrer un commentaire