svelte-virtual-list icon indicating copy to clipboard operation
svelte-virtual-list copied to clipboard

Get index of the item

Open lisabeyy opened this issue 5 years ago • 3 comments

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

lisabeyy avatar Jan 15 '20 16:01 lisabeyy

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'.

apurvjain95 avatar Jan 16 '20 06:01 apurvjain95

Any update on this? I see three PRs above that could potentially help but none of them got merged.

isaiahscheel avatar Aug 11 '22 18:08 isaiahscheel

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>

m1212e avatar Mar 07 '23 11:03 m1212e