dropdown that populates another dropdown

Hi guys,
I’m starting to create a personal site with wix for the first time, I was trying to create a search form with 2 dropdowns, an output table and a dataset created by me. The search works my problem and that by selecting an option in the dropdown1, the dropdown2 does not populate with the related information. Do you have any advice? at the moment my wix code is:


import wixData from ‘wix-data’;

$w.onReady( function () {
uniqueDropDown1();
});

function uniqueDropDown1 (){
wixData.query(“collection”)
.limit(1000)
.find()
.then(results => {

const uniqueTitles = getUniqueTitles(results.items);
$w(“#dropdown1”).options = buildOptions(uniqueTitles);
});

function getUniqueTitles(items) {
const titlesOnly = items.map(item => item.fieldkey);
return [… new Set(titlesOnly)];
}

function buildOptions(uniqueList) {
return uniqueList.map(curr => {
return {label:curr, value:curr};
});
}
}

export function button1_click(event) {
wixData.query(‘clp’)
.contains(‘tratta’, $w(‘#dropdown2’).value)
.find()
.then(res => {
$w(‘#table1’).rows = res.items;
});
}

export function dropdown1_change(event, $w) {
uniqueDropDown2();
$w(“#dropdown2”).enable();
}

function uniqueDropDown2 (){
wixData.query(“collection”)
.contains(“fieldkey”, $w(“#dropdown1”).value)
.limit(1000)
.find()
.then(results => {

const uniqueTitles = getUniqueTitles(results.items);
$w(“#dropdown2”).options = buildOptions(uniqueTitles);
});

function getUniqueTitles(items) {
const titlesOnly = items.map(item => item.fieldkey);
return [… new Set(titlesOnly)];
}

function buildOptions(uniqueList) {
return uniqueList.map(curr => {
return {label:curr, value:curr};
});
}
}


link: https://lucaesp990.wixsite.com/clpbus/projects