Getting into Wix Code today, and facing an issue as follows.
I’m trying to do a dynamic collection pull into a repeater, based on the button that a user clicks. The collection is set up as follows:
teachers
→ name
→ description
subjects
→ name
teachers_subjects
→ teacherId
→ subjectId
Using a dataset (in the GUI), I can create a repeater that shows all of teachers_subjects, with a display of teachers.name and subjects.name. However, I am unable to assign a filter to teachers_subjects such that only teachers_subjects.subjectId = 123xyz (for example).
Programatically, I have attempted the following:
// Import data library
import wixData from 'wix-data';
// Pretty console log.
function prettyLog (item) {
console.log(JSON.stringify(item, null, 4));
}
// Get teachers
function getTeachers () {
// Grab all records from collection.
return wixData.query("teachers_subjects")
.eq("subjectId", "1a0ada75-ac6f-4fe0-930a-5ed2b50b1fed") // hardcoded for now
.find()
.then( (results) => {
// Create dataobject for repeater.
let repeaterData = [];
// Create data object.
results.items.forEach( (item) => {
repeaterData.push({
"teacherId" : item.teacherId
});
});
return repeaterData;
})
.catch( (err) => {
let errorMsg = err;
console.log(errorMsg);
});
}
$w.onReady(function () {
// Handle creation of new items.
$w("#repeater1").onItemReady( ($w, itemData, index) => {
$w("#text26").text = itemData.teacherId; // this is the problematic line
});
$w("#repeater1").data = getTeachers().then(response => response);
});
My question is this… how can I easily turn $w(“#text26”).text = itemData.teacherId; into $w(“#text26”).text = itemData.teacherName; (where it corresponds with the given item.teacherId)? Normally, this would be easily done using a JOIN, but I’m unclear as to how to do that in the wix-data model.
Thanks in advance!