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

Loops - index value dose not change in "if" statement during iteration #2603

Closed
pmmf85 opened this Issue Jun 20, 2018 · 4 comments

Comments

Projects
None yet
3 participants
@pmmf85

pmmf85 commented Jun 20, 2018

  1. Describe your issue:

I am using each attribute loop to show set of items. I am having issue with displaying some of them when I use if statement in loop based on index of the item in array. Index passed to if statement that checks if item can be shown is always 0.

Simple test case would be:

<div each={val, index in ['a', 'b', 'c', 'd']} if={index}>Item index: {index}, item content: {val}</div>

In case above nothing is displayed. In each iteration the value of index is always 0 and value of the val changes correctly. I guess workaround would be using items.indexOf(val)
I think that previously it was working fine (older version of lib). Am I doing something wrong maybe?

It might be same issue as #2412 but it was reported a while ago and a bit of code might have changed since then.

  1. Can you reproduce the issue?

https://plnkr.co/edit/kSBI01S74MExF21dfW4o?p=preview

  1. On which browser/OS does the issue appear?

Chrome Version 67.0.3396.87 (Official Build) (64-bit)
macOS Sierra (10.12.6)

  1. Which version of Riot does it affect?

For sure in 3.10.2
In 3.9.0 index value was passed fine (at least into if)

  1. How would you tag this issue?
  • Question
  • Bug
  • Discussion
  • Feature request
  • Tip
  • Enhancement
  • Performance

Edit: Updated comment a bit, to make it match example from plnkr.co

@sourcegr

This comment has been minimized.

Contributor

sourcegr commented Jun 20, 2018

Hello @pmmf85,

Please see #2482.

I wouldn't hold my breath until this is fixed :)

You should find a workaround!

@sourcegr

This comment has been minimized.

Contributor

sourcegr commented Jun 20, 2018

Please also note that the workaround proposed by @GianlucaGuarini in the issue you mention (#2412), does not even work in the latest release of Riot.

@GianlucaGuarini GianlucaGuarini added the bug label Jun 20, 2018

@pmmf85

This comment has been minimized.

pmmf85 commented Jun 20, 2018

@sourcegr

Thanks for providing some input.

I think that for now, at least in my case, doing something like will solve the issue:
<div each={val, index in items} if={items.indexOf(val)}>Item index: {parent.items.indexOf(val)}, item content: {val}</div>

GianlucaGuarini added a commit that referenced this issue Jun 20, 2018

@GianlucaGuarini

This comment has been minimized.

Member

GianlucaGuarini commented Jun 20, 2018

@pmmf85 Thank you! It was a bug. The patch has been released in riot@3.10.3

GianlucaGuarini added a commit that referenced this issue Jun 20, 2018

Merge branch 'master' into dev
* master:
  3.10.3
  updated: library size
  fixes #2603
  3.10.2
  updated: library size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment