How can I deep watch a complex nested objects array and easily detect which item has changed? #12966
Unanswered
Syntax-J
asked this question in
Help/Questions
Replies: 1 comment
-
try this const testArray = ref([
{ name: 'A' },
{ name: 'B' },
{ name: 'C' },
{ name: 'D' },
])
const testArray1 = computed(() => JSON.stringify(testArray.value));
watch(testArray1, (n, o) => {
let findChangedObject = JSON.parse(n).find((ob,i)=> {
return ob.name !== JSON.parse(o)[i].name
} )
console.log(findChangedObject);
});
const changeAnItem = () => {
testArray.value[1].name = 'Z'
}
hit changeAnItem on some clicking some button |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Can I just create a watcher for each item in the array?
now i only do this with
deep watch array[0] callback set changed id = 0
deep watch array[1] callback set changed id = 1
........ with for loop
is there an easier way?
Beta Was this translation helpful? Give feedback.
All reactions