You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte/test/runtime/samples/each-block-containing-if/main.html

29 lines
603 B

<ul>
{#each items as item}
{#if filter(item, currentFilter)}
<li>{item.description}</li>
{/if}
{/each}
</ul>
<script>
export default {
data: () => ({
currentFilter: 'completed',
items: [
{ description: 'one', completed: false },
{ description: 'two', completed: false },
{ description: 'three', completed: false }
]
}),
helpers: {
filter ( item, currentFilter ) {
if ( currentFilter === 'all' ) return true;
if ( currentFilter === 'completed' ) return item.completed;
if ( currentFilter === 'active' ) return !item.completed;
}
}
};
</script>