Access has a lot through foreach in computed property in ember

So, I have hasMany defined like this. Quests: DS.hasMany ('quest')
I have a property that each quest must go through and work out a total. The function looks like this:

questXP: function() {
    var amount = 0;

    this.get('quests').forEach(function(item)
    {
        console.log(item.get('xpReward'));
        amount += parseInt(item.get('xpReward'));
    });
    return amount;
}.property('quests'),  

I tried adding async: true for hasMany, but it stops working forEach at all. At the moment, it is three times (I have 3 quests), but he can’t access any of the quest’s properties. My thought is that quests are still loading.

Any ideas on what I'm doing wrong?

+4
source share
1 answer

xpReward. quests.@each.xpReward istead quests.

questXP: function() {
    var amount = 0;

    this.get('quests').forEach(function(item)
    {
        console.log(item.get('xpReward'));
        amount += parseInt(item.get('xpReward'));
    });
    return amount;
}.property('quests.@each.xpReward'),
+4

All Articles