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

[FEATURE] Items loop over an array #2500

Open
esmeetewinkel opened this issue Nov 1, 2024 · 1 comment
Open

[FEATURE] Items loop over an array #2500

esmeetewinkel opened this issue Nov 1, 2024 · 1 comment
Labels
feature Work on app features/modules

Comments

@esmeetewinkel
Copy link
Collaborator

esmeetewinkel commented Nov 1, 2024

What?
It would be handy to be able to loop (using items or data items) over a list which is specified in a local variable as an array my_array = ["item_1", "item_2", "item_3"]. This does almost work currently, but when I put this into an items loop I get the error

error-handler.service.ts:69 ERROR TypeError: Cannot assign to read only property '0' of string 'item_1'

It does work when the list is authored as a json of the form

{"item_1":{"id":"item_1"}, "item_2":{"id":"item_2"}, "item_3":{"id":"item_3"}}

which I can achieve by doing some javascript

@calc(@local.my_array.reduce((acc, item) => ({ ...acc, [item]: { id: item } }), {}))))

Could we interpret arrays like the former like the json above automatically so that items can loop over them and can refer to the individual array items by @item.id?

Why?
PLH Kids TZ use case, but useful in general.

@esmeetewinkel esmeetewinkel added the feature Work on app features/modules label Nov 1, 2024
@jfmcquade
Copy link
Collaborator

#2494 is somewhat relevant here – it includes a tweak to the logic that I think might mean that my_array = [{"id": "item_1"}, {"id": "item_2"}, {"id": "item_3"}] is now supported (somewhere between your desired syntax and the one that currently works, as outlined above. Whether we want to support an array of items without explicit id values is maybe an open question, as the functionality was intended for data list rows which do require an id column.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Work on app features/modules
Projects
None yet
Development

No branches or pull requests

2 participants