0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-11-30 00:46:29 +01:00

Fix 7 GUIs crud example for delete when filtered

This example could delete the incorrect person when a filter was applied. Just an example, but the behavior was confusing when I played with it, so I thought it worth fixing.
This commit is contained in:
Jacob Wright 2019-06-10 15:44:50 -06:00 committed by Conv
parent 32107d8102
commit 52b5e05ead

View File

@ -43,10 +43,12 @@
}
function remove() {
people = [...people.slice(0, i), ...people.slice(i + 1)];
// Remove selected person from the source array (people), not the filtered array
const index = people.indexOf(selected);
people = [...people.slice(0, index), ...people.slice(index + 1)];
first = last = '';
i = Math.min(i, people.length - 1);
i = Math.min(i, filteredPeople.length - 2);
}
function reset_inputs(person) {