I’ve created a page intended to allow site visitors to rate the people they worked with on projects. I’ve modified the code from the Velo “Product Reviews” and the “Search a Database” examples to pull information from my data collection (ACFreelancers). Lacking a coding background, I’m receiving the following errors:
- Loading the code for the HOME page. To debug this code, open visv2.js in Developer Tools.
- Loading the code for the Expert Reviews page. To debug this code, open lkftf.js in Developer Tools.
- TypeError: Cannot read property ‘title’ of undefined
If someone could look at my code and let me know what I need to correct, I would appreciate it. Following is the code:
import wixData from "wix-data";
$w.onReady(() => {
loadACFreelancers();
});
let lastFilterExpertise;
let lastFilterCategory;
let debounceTimer;
export function iExpertise_keyPress(event) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w('#iExpertise').value, lastFilterCategory);
}, 500);
}
export function iCategory_click_1(event) {
filter(lastFilterExpertise, $w('#iCategory').value);
}
function filter(expertise, category) {
if (lastFilterExpertise !== expertise || lastFilterCategory !== category) {
let newFilter = wixData.filter();
if (expertise)
newFilter = newFilter.contains('expertise', expertise);
if (category)
newFilter = newFilter.contains('category', category);
const filterValue = $w("#iCategory").value
const byAssignment = wixData.filter().contains("assignment", filterValue)
const byHumanities = wixData.filter().contains("humanities", filterValue)
const bySocialSciences = wixData.filter().contains("socialSciences", filterValue)
const byTopics = wixData.filter().contains("topics", filterValue)
const byOther = wixData.filter().contains("other", filterValue)
$w("#dataset1").setFilter(byAssignment.or(byHumanities).or(bySocialSciences).or(byTopics).or(byOther))
$w('#dataset1').setFilter(newFilter);
lastFilterExpertise = expertise;
lastFilterCategory = category;
}
}
function loadACFreelancers() {
wixData.query('ACFreelancers')
.limit(1000)
.ascending("category")
.distinct("category")
.then(results => {
let distinctList = buildOptions(results.items);
// unshift() is like push(), but it prepends an item at the beginning of an array
distinctList.unshift({ "value": '', "label": 'Select Category' });
// Call the function that builds the options list from the unique titles
$w("#iCategory").options = distinctList;
});
}
function buildOptions(items) {
return items.map(curr => {
// Use the map method to build the options list in the format {label:uniqueTitle, value:uniqueTitle}
return { label: curr, value: curr };
});
}
export function repeater1_itemReady($item, itemData, index) {
let currentPrice = itemData.hourlyRate3;
let newPrice = "$" + formatNumber_AsDollar(currentPrice);
$item("#priceText").text = newPrice
function formatNumber_AsDollar (x) {
return x.toString().replace(/\D(?=(\d{3})+(?!\d))/g, ",");
}
}