Question:
I am trying to filter a dataset named Mentors dataset on a referenced field named Status so that only items with a Status of “Live” appear in the repeater named mentorRepeater. I am lost on how to do this and would appreciate help - I am still fairly new to Velo. Thank you.
Product:
Editor X
What are you trying to achieve:
Filtering on a referenced field.
What have you already tried:
Some code from Chat GPT which does not work.
Additional information:
None
Have you tried using the add filter through the editor
Yes - you cannot filter on a referenced field via editor - if possible it will require code.
I was unaware of this. Good to know as I will need to do this for an upcoming project I need to work on.
Maybe this code will work
import wixData from 'wix-data';
$w.onReady(function () {
wixData.query('MyCollection') //change to your correct collection
.eq('status', 'Available')
.find()
.then((results) => {
$w('#myRepeater').data = results.items; //change to your correct repeater
})
.catch((err) => {
// handle the error
});
$w('#myRepeater').onItemReady(($item, itemData, index) => { //change to your correct repeater
$item('#myText').text = itemData.title; //change to your element
});
});
Had it stored in my code bible, but have never used it or tested it. Cant remember where I researched it originally.
Currently my repeater is tied to a dataset. This code populates straight from a collection w/o a dataset - something I have previously not done. Do I need to disconnect the repeater from dataset? I also do not understand what the last tow lines of code are doing. Is that simply where I would tie repeater elements to field values in collection which replaces purpose of dataset?