mirror of
https://github.com/sveltejs/svelte.git
synced 2024-12-01 17:30:59 +01:00
fix crud example
This commit is contained in:
parent
f863a5df30
commit
a0e72db86a
@ -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>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user