Dear all,
Let me start off by saying that I am a beginner Velo/javascript user, but I try to get the most out of all the forums and API guides that I find… but this still remains a problem for me. I’ll try to explain a bit more.
SCOPE: Having two repeaters on a page, connected to two datasets. One dataset is a list of 653 articles that all have different authors, listed as either names in a single field separated by commas, or ID numbers, still in one field. They would look like this:
John Doe, Margaret Doe
123456789, 987654321
The second dataset is just a list of 7 authors, with an ID and a picture. These names all appear among the 653 entries of the first dataset.
PLAN: The first repeater show a list of articles, pulling data from the database through a datawix.filter function and user input keywords. The filtering function works well and gives me the expected results. The second repeater would be on the side and it should display the picture of 1 or more of the 7 authors in database 2, if they are matching the filtered item. This is a screenshot of the graphic, in orange repeater filtered and in grey the second repeater.
Basically from the first entry I have a list of 8-9 authors, I need those identities to be checked on database 2 and if one matches the second repeater will show the picture. This is a graphical way to show for a huge database which of the 7 major authors participated in that specific result.
WHERE I AM STUCK: I am stuck at the second repeater. I cannot find a way to use the results of the first filter as a way to filter to pull data from the other database. As of now I just have this code (simple filter).
import { local } from ‘wix-storage’
import wixData from ‘wix-data’ ;
$w . onReady ( function () {
$w ( “#searchBar” ). value = “” ;
$w ( “#searchBar” ). placeholder = “calcium, ED, Hajnockzy…” ;
$w ( “#dataset1” ). onReady ( function () {
search ();
});
});
export function searchButton_click ( event ) {
search ();
}
export function resetButton_click ( event ) {
$w ( ‘#searchBar’ ). value = “”
$w ( ‘#searchBar’ ). placeholder = “calcium, ED, Hajnockzy…”
$w ( ‘#counter’ ). hide ()
search ()
}
function search () {
$w ( ‘#searchGIF’ ). show ();
$w ( ‘#dataset1’ ). setFilter ( wixData . filter (). contains ( “title” , $w ( “#searchBar” ). value )
. or ( wixData . filter (). contains ( “sourceTitle” , $w ( “#searchBar” ). value )))
. then (() => {
count ();
})
}
function count () {
let total = $w ( ‘#dataset1’ ). getTotalCount ();
if ( total > 1 ) {
$w ( ‘#counter’ ). text = ${ total } results were found.
;
$w ( “#searchGIF” ). hide ();
$w ( ‘#counter’ ). show ();
}
if ( total === 1 ) {
$w ( ‘#counter’ ). text = ${ total } result was found.
;
$w ( “#searchGIF” ). hide ();
$w ( ‘#counter’ ). show ();
}
if ( total === 0 ) {
$w ( ‘#counter’ ). text = “No result found!” ;
$w ( “#searchGIF” ). hide ();
$w ( ‘#counter’ ). show ();
}
}
Since the filter results are not stored, I don’t know how to find a way to save them in a string or something. The idea would be to have in parallel a query on the same database 1 with the same parameters of the filter. This should give me the same results that I can attribute to a variable, store it and use it for a second function as a “contain” condition. When a match is found in database 2, the picture would show up.
Is that possible?? Am I off path? Also, where do I find exactly that information from the query results? Like how do I pull the author information values out of the query? DO I need to reference the name of the field of the database?
I really hope someone can help me or point me in the right direction!! Thank you so much!
Marco