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

Cannot access object property within template, key is not defined #125

Closed
1 of 7 tasks
bradisbell opened this issue Aug 7, 2019 · 1 comment
Closed
1 of 7 tasks

Comments

@bradisbell
Copy link

Suppose I have a simple loop:

<button each="{key in  ['a', 'b', 'c']}">{state.test[key].text}</button>

With the following state:

      state: {
        test: {
          a: {text:'A Text'},
          b: {text:'B Text'},
          c: {text:'C Text'}
        }
      }

I would expect to see three buttons titled, "A Text", "B Text", and "C Text". Instead, I get a browser error:

Uncaught (in promise) ReferenceError: key is not defined

That seems to be due to Riot.js not understanding how to handle key. I think it should be replaced with scope.key. Instead, this is what turns up in the compiled template:

          'evaluate': function(scope) {
            return scope.state.test[key].text;
          }

Interestingly enough though, if you remove the need for the .text property, the loop works as expected.

  1. Can you reproduce the issue?

https://next.plnkr.co/edit/1GKbFAW5FY0oabgD

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

Chrome on Windows

  1. Which version of Riot does it affect?

v4

  1. How would you tag this issue?
  • Question
  • Bug
  • Discussion
  • Feature request
  • Tip
  • Enhancement
  • Performance
@GianlucaGuarini
Copy link
Member

thank you @bradisbell it's a compiler issue and I am on it. I will transfer the issue to the proper repo

@GianlucaGuarini GianlucaGuarini transferred this issue from riot/riot Aug 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants