javascript - Combine items in array by their key -


i using ember data items cart. these items may this

[   {     "item_id":"5635",     "raffle_purchase_id":"1060",     "item_name":"***",     "item_desc":"***",     "item_image":"5635-ilbt8xngsd-cropped.png",     "item_amt":"2",     "item_type":"raffle"   },   {     "item_id":"5635",     "raffle_purchase_id":"1061",     "item_name":"***",     "item_desc":"***",     "item_image":"5635-ilbt8xngsd-cropped.png",     "item_amt":"4",     "item_type":"raffle"   },   {     "item_id":"5635",     "raffle_purchase_id":"1563",     "item_name":"***",     "item_desc":"***",     "item_image":"5635-ilbt8xngsd-cropped.png",     "item_amt":"2",     "item_type":"raffle"   },   ... ] 

each item here has different purchase id need update on server side need send items update server. when i'm displaying these don't want show every line of same purchase on , on again. rather want combine , calculate total purchases cost.

each item has item id, in case same these 3 (and potentially more) items, , there might handful of other purchases of same item multiple times want same thing to.

basically need items here have same id, total sum of item_amt property, , combine them , show 1 line item total.

i'm little lost on 1 start , this. return coming route in model hook know can whatever processing need before setting model. want make sure keep original items intact (as need know unique raffle_purchase_id's) later when user paying these.

could use for loop go through array , add of items same purchase_id hardcoded parameter array, , loop through new array , find sum of item_amt of each of them adding value variable sum?


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -