I am new to Backbone and facing one issue in which i need to calculate the specific values of my models inside my collection.
For the reference, I am pasting the collection of accounts, from which I need to calculate the sum of acquisitionCost
, units
and netGainLoss
of all the models.
i.e after calculating the acquisitionCost
, I should get: 1900 and one thing we need to take care is the values are coming in string form like shown in the JSON.
{
"accounts": [{
"accountNumber": "AS10000642",
"assets": [{
"assetName": "ABCDEF GHIJKLM",
"isin": "GB0008533564",
"grossProfit": [{
"acquisitionCost": "500",
"units": "10",
"netGainLoss": "20"
}]
}]
},
{
"accountNumber": "AS10000642",
"assets": [{
"assetName": "ABCDEF GHIJKLM",
"isin": "GB0008533564",
"grossProfit": [{
"acquisitionCost": "1000",
"units": "10",
"netGainLoss": "20"
}]
}]
},
{
"accountNumber": "AS10000407",
"assets": [{
"assetName": "ABCDEF GHIJKLM",
"isin": "GB0008533564",
"grossProfit": [{
"acquisitionCost": "400",
"units": "10",
"netGainLoss": "20"
}]
}]
}
]
}