Question with arrays

Gosh do i feel i’m spending too much time searching basic stuff sometimes… (Really trying not to post random questions in here). Anyways, i couldn’t find an answer.

I have a variable (var1) with json in it. it’s an array of “options” built like so :

option_id (integer), type (text), text_value (text).

With dmx-text (or “in text” with {{ }}), i want to be able to give it an id and replace that id with the text value from my var1 variable. In the following example (that does not work), i replaced the external id var by “26” which is an existing “option_id” in var1.

<span scope="col" dmx-text="var1.value.find(item => item.option_id === 26).text_value"></span>

I may be doing it wrong, but my goal is just to find option_id 26 and print the “text_value” field associated with this option_id.

This example with static values, works…

<span scope="col" dmx-text="var1.value.[0].text_value"></span>
([0] or any entry via index)

Thanks for your time and help :slight_smile:

Hey!

What do you mean by that?

You can use the array component and then use the data view.
If you have a .json or a server connect data, you can select it as Data Source

1 Like

If you’re on the beta extensions channel, there’s a filter formatter available there, so your expression will look like:

dmx-text="var1.value.filter(`option_id==26`)[0].text_value"

another option is to use the where formatter:

dmx-text="var1.value.where(`option_id`, 26, '==')[0].text_value"
1 Like

Wow… Thank you so much @franse (your solution will help me a lot for external data) and @Teodor … I learned new stuff today again :slight_smile:

2 Likes

Ooohhh, @teodor, tell us more about the filter formatter! :tada:

There’s nothing much to say, you can test it yourself in Wappler 6 beta on the beta extensions channel: