1👍
✅
Use map
function instead of forEach
:
this.$store.commit(
'deleteCheckboxItems',
response.data.items.map(({id}) => id)
);
Your filter
function also needs some changes. It should return a boolean, but you forgot to return the value.
deleteCheckboxItems(state, payload) {
console.log(payload);
if (state.filteredBrands) {
state.filteredBrands = state.filteredBrands.filter((item) => {
return item.id == payload;
});
}
}
Also payload maybe an array of ids, and you should use some functions like includes
to check your condition.
1👍
if you don’t want to change your implementation of deleteCheckboxItems
to take an array wrap the this.$store.commit
with the for each like this:
response.data.items.forEach(element => { this.$store.commit('deleteCheckboxItems', element) });
Furthermore, the more important one is that your filteredBrands.filter
does not filter since you do not return a value. You have to return item.id === payload
.
Source:stackexchange.com