I am trying to mutate my array after updating objects with the new values. Currently when I use splice()
it has been for only mutating single object. Perhaps I am looking for simple javascript method but I am trying to figure out how mutate array if I am updating multiple objects simultaneously?
This is the store action I am using to commit
response.data
updateCheckedEngagements(context, checkedEnagements) {
axios.patch('/engagementsarray', {
engagements: checkedEnagements.engagements,
assigned_to: checkedEnagements.assigned_to,
status: checkedEnagements.status
})
.then(response => {
console.log(response.data)
context.commit('updateCheckedEngagements', response.data)
})
.catch(error => {
console.log(error.response.data)
})
},
here is the mutation I have currently set up but I do not think it is correct
updateCheckedEngagements(state, engagement) {
const index = state.engagements.findIndex(item => item.id == engagement.id);
state.engagements.splice(index, 1, {
'id': engagement.id,
'assigned_to': engagement.assigned_to,
'status': engagement.status,
})
},
Also since I am passing checkedEngagements
as my parameter in the store action, does that also have to be the 2nd parameter for the mutation?