I have following array with me where records are shown per user
let data = [
{ userid: 1, placename: abc, price: 10 },
{ userid: 1, placename: pqr, price: 20 },
{ userid: 1, placename: xyz , price: 30},
{ userid: 2, placename: abc , price: 40},
{ userid: 2, placename: lmn , price: 50}
So, I want to transpose this data group by userid, by concatenation of place name and sum of price.
It should be look like below
UseId PlaceName Price
1 abc,xyz,pqr 60
2 abc,lmn 90
And I am binding this data to bootstrap vue b-table component
As of now I have done like this
groupby: function(array, key) {
const result = {};
array.forEach(item => {
if (!result[item[key]]) {
result[item[key]] = [];
}
result[item[key]].push(item);
});
return result;
},
And calling this while view is getting initialized,
groupby(this.list,'userid');
though I am getting all records in row as per user, but I am not able to concatenate the values and doing total.
While binding to table it is giving error 'Expected Arrat,got object'
Is anything missing here !
Any help on this appreciated !
question from:
https://stackoverflow.com/questions/66051282/concatenate-array-in-vue-js