Get index of the item
Hi,
We can set a let:item , is there a way to retrieve the index when looping through the items.
Thanks a lot.
Kindest regards,
Lisa
I am not sure whether virtual-list provides something like this by default but how about using something like: "main array object".indexOf(item); where "main array object" is the object you specified as items={"main array object"} as VirtualList prop. You can use this inside the VirtualList tags so it will run for each 'item'.
Any update on this? I see three PRs above that could potentially help but none of them got merged.
In the meantime, this quick workaround does the trick:
<VirtualList items={items.map((e, i) => [e, i])} let:item>
<slot
item={item[0]}
index={item[1]}
/>
</VirtualList>