Only show data in a repeat from an array

The title might be a little weird here, but what I’m trying to achieve is pretty simple.

I have a simple query that brings back many entries, each entry has its own section in a dmx-repeat. Code snipped:

 <li dmx-repeat:repeattest="getMyUserData.data.test">
      <a dmx-bind:href="'"><i dmx-bind:data-feather="" class="align-self-center menu-icon"></i><span>{{projectID}}</span></a>
 </li>

In this the getMyUserData.data.test MySQL query, each column has an ID. Users can select IDs which then get added to array.

Is it possible to make it so the repeat only creates itself where there is the ID in the array?

Using something like <li dmx-repeat:repeattest="getMyUserData.data.test" dmx-show="(projectID == **myArrayHere**)"> works, but only for the first ID in the array, and not the rest.

I know I could use filters on the query, but the same serverconnect is used in multiple places for different things, so it wouldn’t be feasible, my only other option is to create similar serverconnects where I need them, but I’d rather do it this way since its much more clean (and less of the same queries)

Use the .where formatter when building the dmx-repeat:repeattest expression

I tried this too, actually - but it returns no results at all.

What about something like this? I wrapped whatever’s inside the <li> into a <span>

 <li dmx-repeat:repeattest="getMyUserData.data.test">
      <span dmx-show="projectID > 0"><a dmx-bind:href="'"><i dmx-bind:data-feather="" class="align-self-center menu-icon"></i><span>{{projectID}}</span></a></span>
 </li>

You might need to tune the dmx-show expression depending on your data

Ah! I hadn’t even thought about doing it that way - I’ll give it a try and report back, thanks.

As @Apple suggests you should be able to use a .where()

Something like this on the end of your repeat expression

.where('projectID',array.items,'inArray')

I’ve just managed to fix it the minute you sent that.

The problem seems to be that I was setting the array contents when the serverconnect that gets the data for the repeat loads (Success Dynamic Event), so when the repeat was getting its data the array was actually empty, as it only updated afterwards. I guess this doesn’t automatically update.

I moved some things around, and now it works correctly.

1 Like