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

Unable to use iteration value for keyed {#each} blocks #1372

Closed
tivac opened this issue Apr 26, 2018 · 1 comment
Closed

Unable to use iteration value for keyed {#each} blocks #1372

tivac opened this issue Apr 26, 2018 · 1 comment

Comments

@tivac
Copy link
Contributor

tivac commented Apr 26, 2018

Trying to convert a JS object into a keyed each block in svelte, but the compiler/REPL are both yelling at me about the syntax. Attempting it with or without destructuring doesn't appear to matter, but I tried both for good measure.

<!-- Without Destructuring -->
{#each Object.entries(objects) as object (object[0])}
<div>{object[0]}, {object[1]}</div>
{/each}

<!-- With Destructuring -->
{#each Object.entries(objects) as [ key, data ] (key)}
<div>{key}, {data}</div>
{/each}

<script>
export default {
    data : () => ({
         objects : {
            "1" : "one",
            "2" : "two",
        }
    })
};
</script>

REPL version

Do keyed each blocks only support sub-properties of the current iteration value? I can re-structure my data to support that but it seems like the iteration value (or any destructured values from the iteration value) should be valid to use as the key.

@tivac tivac changed the title Unable to use object keys for keyed {#each} blocks Unable to use iteration value for keyed {#each} blocks Apr 26, 2018
@tivac
Copy link
Contributor Author

tivac commented Apr 26, 2018

Whoops, this is a dupe of #703

@tivac tivac closed this as completed Apr 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant