mercredi 23 décembre 2015

Computed property that returns a sum of a property on each model

I have a cart model then has items in it that looks something like this

[
    {
        "item_id": 1,
        "item_name":"Item 1",
        "item_price": 500
    },
    {
        "item_id": 2,
        "item_name": "Item 2",
        "item_price": 230
    },
    {
        "item_id": 3,
        "item_name": "Item 3",
        "item_price": 150
    }
]

I need to sum up the item_price property to be able to display it and then pass it along to ember data or an ajax call to complete a purchase.

Not sure if I'm just not understanding the agregate data thing with computeds but I am trying with this

totalDue: Ember.computed.sum('model.@each.item_price')

On the controller but it's returning 0




Aucun commentaire:

Enregistrer un commentaire