How to convert promis to object


#1

i have promis object that i get after fetching data from server, how can i convert him to js object and fetch from him all the records ?


#2

I assume you’re referring to the DS.PromiseObject from ember-data. I believe the recommended way be to use .then on the promise. For example:

actions: {
  messageAuthor() {
     this.get('article.author').then(author => { 
       author.messageAuthor();
     });
   }
})

Now this action is asynchronous, even if it doesn’t hit the server. If you do need to use it synchronous, you could do get('content') on the promise. Eg this.get('article.author.content'). That will get the underlying record for the author, but I really don’t recommend that. Use it sparingly if you have to. 1) I don’t think that’s completely “public API”. 2) There is no guarantee that the content will be ready. If the author hasn’t come back from the server yet, you might end up with null.


#3

i have promise object that i have inside result… model… store… records i want to fetch the records