Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get index of the item #37

Open
lisabeyy opened this issue Jan 15, 2020 · 3 comments · May be fixed by #40 or #65
Open

Get index of the item #37

lisabeyy opened this issue Jan 15, 2020 · 3 comments · May be fixed by #40 or #65

Comments

@lisabeyy
Copy link

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

@apurvjain95
Copy link

apurvjain95 commented Jan 16, 2020

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

@osamamaruf osamamaruf linked a pull request Mar 18, 2020 that will close this issue
@Ivo-Evans Ivo-Evans mentioned this issue Feb 15, 2022
@isaiahscheel
Copy link

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

@fabiot21 fabiot21 linked a pull request Mar 1, 2023 that will close this issue
@m1212e
Copy link

m1212e commented Mar 7, 2023

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants