lundi 15 octobre 2018

Ember.js: Converting vanilla array into Ember array not working

I have an array that I'm converting to Ember array with A() as I want to use some of Ember array methods, like filterBy(), but it's not producing the result I want. What is the proper way to convert a vanilla array into an Ember array?

Ember:

import Component from '@ember/component';
import { computed } from '@ember/object';
import { A } from '@ember/array';

export default Component.extend({
  movieGenreIds: computed.map('movies', function(movie, index) {
    return movie.genre_ids;
  }),

  genresNames: computed('movieGenreIds', 'allGenres', function() {
    let genresArray = A(this.get('genres')); // <--- conversion here

    this.get('movieGenreIds').forEach((movieGenreId, movieGenreIndex) => {
      console.log('MOVIE_GENRE_IDS!!!', genresArray);
      console.log('FILTERBY ID^^^', genresArray.filterBy('id', movieGenreIds.toString())); // <-- not returning desired results
    });
  }),
});

Ember route (data is from themoviedb api and models represent the data structure in the json provided):

import Route from '@ember/routing/route';
import RSVP from 'rsvp'

export default Route.extend({
  model() {
    return RSVP.hash({
      movies: this.store.findAll('movie'),
      genres: this.store.findAll('genre'),
    })
    .then(data => data);
  },
});




Aucun commentaire:

Enregistrer un commentaire