Filter Dynmic page with search

hello,
I’m trying to do dynamic page search from to sparated fileds.
I have 2 datacollections:

  1. items
  2. itemCategories

I just want to be able to use the itemCategories to filter the items on the page.
i just tring to use the following code :

import wixData from ‘wix-data’;

$w.onReady(() => {
wixData.query(‘itemCategories’)
.find()
.then(res => {
let options = [{“value”: ‘’, ‘cat_name’: ‘כל הקטגוריות’}];
options.push(…res.items.map(cat_name => {
return {‘value’ : cat_name.title, ‘cat_name’: cat_name.title};
}));
$w(‘#icatname’).options = options;
})
});

let lastFilterTitle;
let lastFilterCatname;

let debounceTimer
export function itemsearch_keyPress(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;

} 
debounceTimer = setTimeout(() => { 
        filter($w('#itemsearch').value ,lastFilterCatname); 
}, 200); 

}
function filter (title, cat_name) {
if (lastFilterTitle !== title || lastFilterCatname !== cat_name) {
let newFilter = wixData.filter();
if (title)
newFilter = newFilter.contains(‘title’, title);
if (cat_name)
newFilter = newFilter.eq(‘cat_name’, cat_name);
$w(‘#dataset1’).setFilter(newFilter);
lastFilterTitle = title;
lastFilterCatname = cat_name;
}
}

export function icatname_change(event, $w) {
filter(lastFilterTitle, $w(‘#icatname’).value);
}

But i can only search by the items not the categories, what do i did wrong??

Please advice.

Hey,
I’m afraid that we’re unable to provide complex debugging of your code. We are able to provide guidance for using the Wix Code platform. Can you please be more specific about what you were struggling with?
You can check out this article to learn more about debugging your code.

Thanks,
Tal.