Skip to content

Computed value in DS.Model returns Promise instead of Value #1315

azhang opened this Issue Sep 16, 2013 · 2 comments

2 participants

azhang commented Sep 16, 2013

more specific details here:

I'm trying to show a computed value in my template, but since the computed value uses an async linked model, it returns a promise. Is there any way to get or set the value when the promise is fulfilled?

Ember.js member
wycats commented Sep 18, 2013

You can try something like this:

App.Survey = DS.Model.extend({
  title: DS.attr(),
  owner: DS.belongsTo('user'),
  questions: DS.hasMany({ async:true }),

  totalResponses: Ember.arrayComputed('questions', {
    initialValue: 0,
    addedItem: function(accum, item) {
      accum += item.get('totalResponses');
    removedItem: function(accum, item) {
      accum -= item.get('totalResponses');

When questions resolves, the addedItem callback in totalResponses will be called once for every item in the resolved array.

@wycats wycats closed this Sep 18, 2013
azhang commented Sep 18, 2013

thanks! I'll try that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.