IDEMSInternational / open-app-builder

PLH App Frontend
GNU General Public License v3.0
8 stars 25 forks source link

[FEATURE] Items loop over an array #2500

Open esmeetewinkel opened 2 weeks ago

esmeetewinkel commented 2 weeks ago

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.

jfmcquade commented 1 week ago

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.