I have a route that initially has no suggestion. Based on an action, I would like to grab a suggestions array with Ember Data, get the first suggestion and assign it to the controller. Here's what I've got:
App.IndexRoute = Ember.Route.extend({
setupController: function(controller, model) {
this._super(controller, model);
controller.set('suggestion', null);
},
actions: {
getSuggestion: function() {
suggestion = this.store.find('suggestion').then(function(s) {
return s.get('firstObject');
});
this.controller.set('suggestion', suggestion);
}
}
});
The problem is that the suggestion variable, after performing the getSuggestion action, it still a promise. How can I only set the controller variable after the promise is resolved? Or how can I let it resolve afterwards and have the variable updated with the actual object?
Set the property on resolution of the promise:
actions: {
getSuggestion: function() {
var self = this;
this.store.find('suggestion').then(function(s) {
self.controller.set('suggestion', s.get('firstObject'));
});
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With