How can I filter an array in an array?

I’m trying to retrieve just one of the threadMessage items in the nested array. This threadMessage could have multiple items in the array, but each item will have the same ThreadId.

For some reason I’m having a challenging time trying to filter this properly.

I’ve tried both a data view and multiple iterations of queries in a repeat. But neither have been successful.

Here’s a data view
image

Here’s the query in a repeat.
Emails.data.threadMessages.where('threadMessage.ThreadId','18d674721eab158d','==')"

You need to do this on the client side?
I could be wrong but seen some topics with no certain answer.

On server side you can use join, split and the In condition.

Client side, this is in a Capacitor app.

Emails.data.threadMessages.where(‘threadMessage.ThreadId’,‘18d674721eab158d’,’==’)"
Keith you copied this value from the code editor or from inside the binding panel?

Because if I guess correct from the ending double quotes it must be straight from the editor…
I think that the property name should be enclosed in backquotes and not single quotes…
‘threadMessage.ThreadId’ this should be in the editor window:
threadMessage.ThreadId
Can you check it please?

I’m writing in code view. Wappler’s binding panel can’t handle these expressions. It actually corrupts some of them if I open the in Data Bindings panel. :slight_smile:

I’m getting closer. This returns the first threadMessage. I’ve done similar expressions before I just need to figure out why the .where isn’t working correctly.
Emails.data.threadMessages[0].threadMessage

For what I remember, where doesn't work on a nested array.
You're using sqlite?

NOooooooooooooo! :slight_smile:

I thought I’ve done this before. But I could be wrong.

I am able to do fairly complex expressions like this.
threadMessages.data.threadMessages.where('ThreadId', query.t, '==')[0].LabelIds.parseJSON().where('$value','STARRED','contains').values('$value')=='STARRED'"

I haven’t had any issues on any other expressions using single quotes. I did try your suggestion of switching it to back ticks, but it didn’t change anything.

1 Like

Since this works.

Emails.data.threadMessages[0].threadMessage

I was hoping there was a way to dot walk into the nested array with a where like this, but maybe @franse is right that it’s not possible. I’m hoping I’m just not writing it properly.

Emails.data.threadMessages.where('threadMessage.ThreadId','18d6b1e52dbc3bcf','==')[0].threadMessage

Maybe this part of the where is not possible. .where('threadMessage.ThreadId'.

I saw it on a few posts when I was looking for some info to help you out with this, but I'm not 100% sure.

If you are using sqlite, what about using join, split, and in, on the condition?
I don't want to lie, but I think its possible.

Hi @george, can the team confirm if this is possible and I'm just writing the expression wrong?

Dot notation is not supported in Wappler, you need a custom formatter

There was a related discussion here:

But I see comments of yours in that topic saying nesting works for you? I don't know, maybe you dreamed or misinterpreted :laughing: (probably you were referring to dot-notation for accessing variables, but not as an argument for the .where formatter)

It’s entirely possible I’m a dummy and gave the wrong advice in that topic. :grimacing:

Please try this expression:

Emails.data.threadMessages[0].where('ThreadId','18d6b1e52dbc3bcf','==')[0]

Edit: Bah, WAIT

The ThreadId is one level down though. It’s Emails.data.threadMessages.threadMessage.ThreadId

@kfawcett

Im pretty sure I have done something like this in the past

Maybe it needs some logic fix, but with join and split you can maybe use the IN condition.

1 Like

I might have it. Just seeing if I can get it to work with a variable.

Here’s the working expression. So I was right that .where() can work without a custom formatter. Thanks for refreshing my dusty memory @Apple! :slight_smile:

Emails.data.threadMessages.where('threadMessage[0].ThreadId',query.t,'==')[0].threadMessage

The first .where() needed to target the first item in the threadMessages array to return the threadMessage array where it’s ThreadId equals the query.t value.

3 Likes