-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
{{#each things as thing by thing}} #703
Comments
I actually really hate this in AngularJS. I can never get it right, and the documentation is very unclear. The only support I'd want to see is the ability to iterate Objects by key, which could be done in a simple, javascripty way:
|
It seems #704 canonizes the Since |
I like the idea of this as I could imagine reusing a key function that gets passed around to various places |
I've got a few thoughts about each of the current proposals:
Looks like you forgot to type a value after the
Keyed updates are already using the For this particular use-case I'd expect something like
Which clearly illustrates the intent of using |
I'd like to add that, if there's any doubt as to the desirability of this feature, it'd be really useful for generic reusable components which act upon arrays of varying objects. For instance, user code might provide an array of objects of any kind to a reusable component, and could specify the unique key, or a method to generate the unique key, for each object, for the reusable component to use. On the matter of syntax, I feel that {{#each things as thing by 'key'}}
{{#each things as thing by keyProperty}}
{{#each things as thing by options.key}}
{{#each things as thing by thing.getKey()}}
{{#each things as thing by getKey(thing)}} I don't think the existence of the current I can't comment on the feasibility, but I hope it's not problematic. So, I think there's pretty good reason, both for this feature as a concept, and for its implementation with the |
Something related here but not mentioned is that we will need to have keyed each block support using an array index too. For larger lists I always get the value from the server the fastest way possible as a json array of array of values only (rather than an array of objects with the keys being repeated for every single row).
|
I assume that'd be supported by the
This seems like the most flexible approach-- and I like the fact that it doesn't use sigils. |
Seems like this was closed by #1318? https://svelte.technology/guide#keyed-each-blocks {#each things as thing (thing.key)} |
The syntax has changed, but what's actually permitted as a keyed index has not. IMO this should not be closed until arbitrary expressions are allowed as keys. |
Not quite — the syntax is there, but it doesn't currently support any form other than |
dammit @Conduitry. yes, exactly that |
So given that the syntax should be |
allow arbitrary expressions in each block keys
This is implemented in 2.4.0 |
As mentioned in #700, it's sometimes useful to be able to use a list item as the basis for keyed updates, rather than a property of each list item.
That could be done a few different ways, e.g.:
One potentially nice feature of the last option, apart from the fact that it doesn't have off-putting special characters, is that it could be more flexible — as well as
by thing
orby thing.id
it could potentially be any expression:Haven't looked into whether that's feasible. Just wondering about whether it would be desirable if so. Thoughts?
The text was updated successfully, but these errors were encountered: