wixData query against array of correct values

This should be super simple but I just cant find it! I got checkboxes for what website visitors want to see on a leaflet map. The selected choices are placed in an array like this:

selPOIs = [Refuge,Snack Bar,Glacier,Waterfall,Lake]

Now in my query I simply want run a query that returns all items that are of the type that is in the selected list:

wixData . query ( “PointsofInterest” )
. contains ( “type” , selPOIs )
. find ()

Now contains wont work, nor does hasSome. I am looking for .includes but that doesnt seem to exist. I could try to write a for loop and run through each value in the array and run a .contains query against it but there must be a smarter solution? I do need it to come back in one query result as I only want to send the responding search results to the leaflet iframe once.

@philip4554 The data type of the values in that array is text, so they need to have quotes around them. Also, hasSome is the function to use for this purpose.

selPOIs = ["Refuge","Snack Bar","Glacier","Waterfall","Lake"];

I am sorry, I only got to putting the code in now and it is not working. The log shows everything correct but the query is coming back empty. Here is the relevant piece of code. I am using push to add the selected items to an array. I then use the map function to add the " to each entry. I then run the hasSome query but it returns nothing…

if ( $w ( ‘#checkRefuge’ ). checked ) {
selPOIs . push ( “Refuge” );
if ( $w ( ‘#checkSnackBar’ ). checked ) {
selPOIs . push ( “Snack Bar” );

console . log ( "selPOIs: "  +  selPOIs ); 

// Add the Quotes to each entry 
selPOIs  =  selPOIs . map ( i  =>  '"'  +  i  +  '"' ); 
console . log ( "Quoted selPOIs: "  +  selPOIs ); 

//Check for empty selPIOs 
**let**  numPOIs  =  selPOIs . length 
console . log ( "numPOIs: "  +  numPOIs ); 

//POIs have been selected 
**if**  ( numPOIs  >  0 ) { 
    console . log ( "POIs have been selected, starting search" ); 

    wixData . query ( "PointsofInterest" ) 
    . hasSome ( "type" , selPOIs ) 
    . find ()          
    . then (( results ) => {

@philip4554 Since you are adding the quotes to items in the push function, there’s no need to add them via the map function.

Thanks. It works now

1 Like