Reputation: 1056
I have a select box which content is a calculated property. For the calculation i have to find some record from the store. Find returns a promise, which has to resolved. but how?
Here is the code:
App.IndexController = Ember.Controller.extend({
selectedCategory:null,
person: function() {
var self = this;
//return [{"id":1,"name":"Dummy"}];
return this.store.find('author',1).then(function(author){
return author;
});
}.property('person'),
actions: {
submit: function() {
//alert("Submitted!");
}
}
});
And the jsBin: http://jsbin.com/pexolude/167/edit
ps.: i know i could make a function, and inside the then
set the person property but i want to learn to resolve and return a promis' result. (if its possible.)
Upvotes: 1
Views: 75
Reputation: 2201
The method you're trying doesn't work because the computed property will return the promise itself, not the thing the promise returns.
This answer details a method that does work (Ember v1.6.1) using just a computed property. Though, it's probably quicker and more readable to simply define set the property from inside an observer, as you noted.
Upvotes: 1