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