[英]How can I iterate over an array in a Svelte store?
我在store.ts
中有一個數組
export let annotations = writable(new Array<Annotation>());
我想在component.svelte
中遍歷數組:
<script lang="ts">
import { annotations } from '../store';
</script>
<section>
{#each annotations as highlight, index}
...
{/each}
</section>
這失敗了:
“Writable<Annotation[]>”類型的參數不可分配給“ArrayLike”類型的參數
這是有道理的 - Writable
object 不是常規數組,它是Writable
。
如何迭代 Svelte 商店中的數組?
在component.svelte
中迭代數組:
<script lang="ts">
import { annotations } from '../store';
</script>
<section>
{#each $annotations as highlight, index}
...
{/each}
</section>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.