How to prefill the content of dropdown from a query?

Hi @scottamesmessinger!

Some queries (usualy SQL based ones) return data as an object of arrays like this:
{ key1: [val, val], key2: [val, val] }

Which would make the selection of all of the values in an array easy as shown above, queryName.data.key1.

Many other data sources return an array of objects like this:
[ { key1: val, key2: val }, { key1: val, key2: val } ]

For this, you could either get the array of all of a certain value by using the .map() JS method, or converting it to an object of arrays using our helper function formatDataAsObject() (there’s also the opposite as formatDataAsArray). That would look like either:

queryName.data.map(d=>d.key1)
or
formatDataAsObject(queryName.data).key1

2 Likes