Jul 4, 2018
2
Level 5
Vue doesn't detect changes on a Javascript array (filter / splice)
Hello,
I am on Vue 2.5.16
I have a JS array of objects at the top of my view , which is populated by my controller. It looks like this :
[{ id: 1}, { id: 2}, { id: 3}, { id: 4}]
I'm using this array at a source for displaying data, and thanks to Vue, it refreshes when I push some data into it.
However, when I try to delete an element from its ID, like so :
let id = 1 // id is retrieved when user clicks on element
if (ajax.readyState === 4 && (ajax.status === 200)) {
myArray = myArray.filter(item => item.id !== id)
}
It doesn't work.
I've read into this : https://forum.vuejs.org/t/vue-js2-renders-array-with---ob---observer/12426/2 and this : https://vuejs.org/v2/guide/list.html
but I cannot make it work.
Any help will be appreciated
Please or to participate in this conversation.