mercredi 4 novembre 2015

Make request inside a map function in ember 2

I'm struggling with the following: So i got a list of ids in a user object, i would like to retrieve the list of users, whose those ids belong to. My idea was to use a map to convert the array of ids to an array of users, I came to the obvious wall. since the call is asynchronous y can't expect the users to be there, however yes the promise. Is there anyway to return this promises in a way that Ember can show the data when they get resolved ? I don't really care when they get resolved. but when they do, that they render the data. What is happening now is that i get a list of Promises, which is fine, and kind of expected, but how do i tell ember, ok when you do resolve the promises show the data?

Thanks in advance

let users = this.get('user.followingIds').map((followerId)=>

                {
                    return this.store.query('user', {user:followerId})
                        .then((user) => {
                            return user;
                        })
                        .catch((e) => {
                            console.error('user catch', e);
                        });

                });
this.set('followers',users);




Aucun commentaire:

Enregistrer un commentaire