Dropdown input on dynamic page with backend query

Hi,

I was wondering if someone would be able to point me in the direction of why I can’t get the below code to filter with the dropdowns?

I have been trying to improve the sites speed and responsiveness and have been trying to use the backend for multiple queries.

Note: pageTitle is the field key for the grades.

Back end

import wixData from 'wix-data';
import wixUsersBackend from 'wix-users-backend';

export function getSearch(field, test) {
 let query = wixData.query("Courses");
 if(test.length > 0) {
        query = query.contains(field, test);
    }
 return query.find();
}

Front end

 
import {getSearch} from 'backend/utilitiesModule';

export function searchButton_click(event) {
//$w('#regionDropdown').value = "all";  
let categoryValue = $w('#dynamicDataset').getCurrentItem().title;
let gradeValue = $w('#gradeDropdown').value;
let regionValue = $w('#regionDropdown').value;
    console.log(regionValue)
    console.log(gradeValue)
    console.log(categoryValue)
    getSearch("coursesCategory", categoryValue && "pageTitle", gradeValue ).then(function (resp) {
 let items = resp.items;
 let courses = [];
        items.forEach(function (item) {
 let course = { "coursesCategory": item.coursesCategory, "rating": item.rating, "_id": item._id, "title": item.title, "image": item.image, "duration": item.duration, "individaulPrice": item.individaulPrice, "lightbox": item.lightbox, "prices": item.prices, "description": item.description, "count": item.count };
            courses.push(course);
        });
        $w('#repeater1').scrollTo();
        $w("#repeater1").data = []; 
        $w("#repeater1").data = courses; 
    });
    $w("#gradeDropdownTwo").value = $w('#gradeDropdown').value;
    $w("#regionDropdownTwo").value = $w('#regionDropdown').value;

}

I have working code

getSearch("pageTitle", gradeValue ).then

but on the dynamic page all of the grades for all trips show not just what is relevant to the current page i.e. rock climbing it would show every trip from hiking, holidays, canoeing etc
so I tried this line but it doesn’t seem to work but no errors.

getSearch("coursesCategory", categoryValue && "pageTitle", gradeValue ).then

In the end, I’m looking to combine two dropdowns, grade and region and the relevant trip category to display the appropriate trips on the dynamic page.

Thank you!

I only had as quick glance, but I do have 3 comments:

  1. In your case not only that using the backend won’t make the process faster, it probably will even make it slightly slower.
  2. Here you put 3 variables:
getSearch("coursesCategory", categoryValue && "pageTitle", gradeValue )

But in the function deceleration you only have 2 variables:

export function getSearch(field, test)

How comes?
3. I guess you meant to use + not &&. Didn’t you?

@J.D. If I’m honest those lines are the ones that confuse me… my coding skills are reasonable for what I have on the site but I wouldn’t say that I particularly truly understand all of the code.

I have been working with this template https://www.wix.com/gramps-workbench/ratings-vw which seems to be instant loading, mines takes a few seconds so thought that I could try to improve that area as I’ve had some comment on the site speed/responsiveness from returning clients so I would expect that it must be more of an issue than I thought :frowning:

I tried

getSearch("coursesCategory", categoryValue + "pageTitle", gradeValue)

but still no results.

@stephenmccall as I said you can’t pass 3 variables to a function, if you set it to get only 2.