Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Closed
aaronz8 opened this Issue · 2 comments

2 participants

@aaronz8

more specific details here: http://stackoverflow.com/questions/18835533/ember-data-model-computed-value-return-value-instead-of-promise

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?

@wycats
Owner

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
@aaronz8

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.