I have a list of global products.
<span v-for="product in products">
{{product.name}}
</span>
I also have sales which contain products.
<div v-for="sale in sales">
<span v-for="product, key in sale.items">
{{product.name}}
</span>
</div>
This prints out a list of all attached products to this sale.
Product #1
Product #2
Product #1
Product #3
Product #2
I want the above list, to display quantities, instead of repeating...like this.
Product #1 x 2
Product #2 x 2
Product #3 x 1
So normally in regular javascript I might do.
for(var i = 0 ; i<=products.length; i++){
var qty = 0;
for(var k =0; k<=sales.items.length; k++){
if(sales.items[k].id==products[i].id){
qty++;
}
}
if(qty!=0){
console.log(products[i].name+" x "+qty);
}
}
But how would I do this in vue.js?
I've tried
<div v-for="sale in sales">
<span v-for="product in products">
<span v-for="prod in sales.items" v-if="product.id==prod.id">
{{product.name}} x {{how do I get quantity here??}}
</span>
</span>
</div>
Obviously thats not gonna work, cuz I need a quantity variable that resets on each loop around the products. How can I do this?