So i hope you tried to study all given tips and here it comes…
I think, this is what you were looking for…
import wixData from 'wix-data';
//-------- USER-INTERFACE -------------------------------------------------
var DBFIELDS = []
var DATABASE = "Team"
var DBLIMIT = 1000
var REPEATER = "repeater1"
//-----------------------------
DBFIELDS[0] = "sprache"; //<---simple adding new TAGS-DATAFIELD here --> 1-st. CBG
DBFIELDS[1] = "bundesland"; //<---simple adding new TAGS-DATAFIELD here --> 2-nd. CBG
//-------- USER-INTERFACE -------------------------------------------------
$w.onReady(()=>{
wixData.query(DATABASE)
.limit(DBLIMIT)
.find()
.then(async(results)=>{console.log(results.items);
let ITEMS = results.items
getUniqueCBGtitles(ITEMS, DBFIELDS[0], "CBG1"); //<--- simple adding new CBG here
getUniqueCBGtitles(ITEMS, DBFIELDS[1], "CBG2"); //<--- simple adding new CBG here
});
$w('#'+REPEATER).onItemReady(async($item, itemData, index) => {
console.log(itemData.sprache)
$item("#imgMain").src = itemData.pic
$item("#txtFirstname").text = itemData.vorname
$item("#txtLastname").text = itemData.name
});
$w('#CBG1, #CBG2').onChange(()=>{
populateRepeater($w('#CBG1').value, $w('#CBG2').value)
});
$w('#btnClear').onClick(()=> {
$w("#CBG1, #CBG2").value = undefined; populateRepeater();
});
});
function populateRepeater(selectedOption1, selectedOption2) {
let dataQuery = wixData.query(DATABASE);
if (selectedOption1.length>0){dataQuery = dataQuery.hasAll(DBFIELDS[0], selectedOption1);}
if (selectedOption2.length>0){dataQuery = dataQuery.hasAll(DBFIELDS[1], selectedOption2);}
dataQuery.find()
.then(results => {
const filteredItems = results.items;
$w('#'+REPEATER).data = filteredItems;
})
}
async function getUniqueCBGtitles(ITEMS, DBFIELD, CBG){
let uniqueTitles = await [...new Set(getxxx(ITEMS).flat())]; $w('#'+CBG).options = buildOptions(uniqueTitles);
function getxxx(items) {const titlesOnly=items.map(item => item[DBFIELD]); return [...new Set(titlesOnly)];}
function buildOptions(item) {return item.map(item => {return {label:item, value:item};});}
}
An working example can be found here…
https://www.media-junkie.com/checkbox-filter
EDIT:
You will have to add a hasSome-filtering functionality if just 1 of 2 CBGs is selected.
Code some kind of a SWITCH (using if-else-queries).
If just one CBG is checked —> switch to —> “hasSome”
else —> switch to —> “hasAll”