Using additionalScope to pass to a query a id of a listview item

  • Goal:
    Hi, I have a nested listview. The first listview shows a list of music tracks and the second listview, show the relatedTracks. I have 2 queries. The first one to getAllTracks. This is the source of the first listview, and the second one to get related Tracks . Specifically this query is:
    SELECT * FROM RelatedTracks WHERE RelatedTrackId = TrackId[i]

As you can see I would like to select all tracks that have in the column RelatedTrackId the Id of the track of the first listview. This means that, each Item of the first listView as a unique id that I need to pass to the query.

  • Steps:
    I tried several ways to do this, but none of them worked.
    I tried to use transformer to combined 2 queries and get a JSON and use that JSON as a source for list view, but I don't understand how transformer works and it gave me no output.
    So I tried storing the id of the track of the firstList view in a variable "trackId" and then use this variable as iterator (example: getRelatedTracks.data.id[trackId] but in this way all relatedTracks have the same data because trackId have only one value.

Last thing I tried is to use additionalScope. So, I created a JS Query that trigger getRelatedTracks and pass to it the id of the main track, but seems that the additionalScope is null.

What I would like to achieve is something like this

Track 1

  • related track 1
  • related track 2
  • related track 3
    Track 2
  • related track 1
  • related track 2
  • related track 3

I don't know how to change the value of additional scope automatically, without triggering the JS Query manually. I would like that for each track, the additional scope changes with the iterator. So when the "i" values of the listTrack changes, also change the additionalScope.

Hope I was clear. I'm not a developer so I think I made some errors.

Can you help me? thank you

Hey @Matteo_Vacca,

To achieve your desired result, I believe the best option is filtering the get related Tracks query using javascript on the datasource of the nested listView.

Here's an example of how you can do this:
image
Replace query 2 with your get related Tracks query, x.related_to with x.RelatedTrackId and item.id with item.TrackId.

Let me know if this helps!

hank you so much for your reply. It seems that the filter for related tracks is working well; it shows related tracks only when they are available, which is great!

Now, the issue is that for each related track, I want to display:

  • Name
  • Artist
  • Album

I'm not sure how to correctly retrieve these values. I tried something like getRelatedTracks.data.name[i], where:

  • getRelatedTracks is the query to fetch all related tracks
  • [i] is the iterator for the trackList (the parent of relatedTrack)

However, this approach results in the same name being displayed for each related track. It works correctly for the first track, but for subsequent related tracks, the values remain the same.

Where am I going wrong?

Hello @Matteo_Vacca,

If you are using getRelatedTracks.data as the datasource for the nested listView you can just use the 'item' property to reference the value retrieved from the database.
To get the name you can use {{ item.name }}