I have three arrays: colour objects, size objects, sku objects. These are fetched from the database using an API call and stored in the Vue data(). I then build a 2D matrix of the sizes and colours with the sku if it exists using the map and find operators
this.sizes.map(
size=> this.colours.map(
colour=>(
this.skus.find(
sku=> sku.sku == this.style.name + colour.colour_code + size.code
) || {sku: this.style.name + colour.colour_code + size.code, selected:false}
)
)
)
I need to assign the results to a new array (this.matrix), however for the UI I also need an additional field (selected:false) that is not in the sku object it does not need to live on the database as it is only for state control. To do this I think I need to use Object.assign({selected:false}, sku) but I can't work out where I would put it in the above code. I have to do it as the this.matrix is assigned, otherwise Vue will not generate the getters and setters
Each cell reference in the 2D array will have 0 or 1 skus in the sku array. Every sku in the sku array will have a corresponding slot in the 2D array.
Where would I put the Object.assign, or is there a better way?