簡體   English   中英

如何迭代 Svelte 商店中的數組?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM