mercredi 28 janvier 2015

Returning a Promise with computed properties

I need to get hold of a value from another ember-data model in a computed property. All my belongsTo and hasMany relations are async : true.I have access to the value, however, it is displaying as '[Object, Object]' when I know the result actually resolves to the correct value from the debugger. I think it is due to my lack of understanding about promises.



displayName : function() {
return this.get('name') + ' ('+ this.get('currentGroup') + ')'; // currentGroup is displaying as '[Object, Object]' as it is pointing to the Promise I think
}.property('name'),

currentGroup : function() {
var promise = this.get('groups').then(function(groups) { //groups is async : true

//Do a bunch of complicated logic to work out a group based
//on the effective start date

return currentGroup.get('name'); // this resolves correctly in the debugger
});

return promise;
}.property()




Aucun commentaire:

Enregistrer un commentaire