繁体   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