mercredi 13 septembre 2017

Ember - findAll and promises

I have a little problem using findAll in my component. It concerns the value it returns at the end.

users: Ember.computed(function() {
return this.get('store').findAll('user');
}),

In my case, I want to get the name of the first object. So in my handlebar:

users.firstObject.name

'users' is a class in this case. But I'm trying to return directly the first object in the property, like this:

user: Ember.computed(function() {
    return this.get('store').findAll('user')
    .then(function(user){
      return user.get('firstObject');
    });
  }),

But in this case, in my handlebar, user.name is undefined and user is a promise. There is something I can't understand with promises, how they work ... Can somebody help me to get the correct user without using 'firstObject' on my users ? Thanks in advance !




Aucun commentaire:

Enregistrer un commentaire