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

fix crud example

This commit is contained in:
Richard Harris 2019-02-17 11:06:28 -05:00
parent f863a5df30
commit a0e72db86a

View File

@ -3,13 +3,22 @@
<script>
export let people = [];
let filteredPeople;
let selected;
let prefix = '';
let first = '';
let last = '';
let i = 0;
$: filteredPeople = prefix
? people.filter(person => {
const name = `${person.last}, ${person.first}`;
return name.toLowerCase().startsWith(prefix.toLowerCase());
})
: people;
$: selected = filteredPeople[i];
$: reset_inputs(selected);
function create() {
people = people.concat({ first, last });
i = people.length - 1;
@ -27,18 +36,8 @@
i = Math.min(i, people.length - 1);
}
$: filteredPeople = prefix
? people.filter(person => {
const name = `${person.last}, ${person.first}`;
return name.toLowerCase().startsWith(prefix.toLowerCase());
})
: people;
$: selected = filteredPeople[i];
$: if (selected) {
first = selected.first;
last = selected.last;
function reset_inputs(person) {
({ first, last } = person);
}
</script>