Iterating over an hash to make an array of values inside a dropdown

Hi,

This is probably an easy question just regarding JS available inside a small box.

I’m attempting to add data to my Postgres DB using data I’m fetching from an API to create new records from a dropdown.

I’ve almost got it working, I’m just having a bit of a hard time figuring out how I can iterate over a hash inside the values and display_value box in a dropdown component.

I’m able to fetch one value with [{{getDeals.data.items[i].data.id}}] this works fine, for one value. I’m just not sure how to map it properly so I can get all the values, eg I tried:

[{{getDeals.data.map(i => items[i].data.id)}}] but I get error in template, map is not a function.

Any suggestions would be helpful.

Thanks

Hey @holden, and welcome to the forum! To help you I’ll need a better sense of the structure of getDeals.data.items - what does that look like? In general, the Dropdown component expects an array of values for the Values input. So something like getDeals.data.items.map(item => item.data.id) or maybe Object.values(getDeals.data.items) could work.

1 Like

Your first one works! I thought it would be simple.

Thanks for that.

2 Likes

Haha awesome!