Question:
I have a repeater with text on a dynamic page. I would like to show feedbacks from an array field from the dataset.
Product:
Wix Studio - Veloc Code - Repeater with Text - Array Field from Dataset
What are you trying to achieve:
I would like to show the array elements which are texts on the repeater of the respected item of the dynamic page.
What have you already tried:
I tried two ways:
1.
$w.onReady(() => {
// Get the dataset connected to the Szakemberek collection
const szakemberekDataset = $w('#szakemberekDataset');
// Wait until the dataset is ready
szakemberekDataset.onReady(() => {
// Get the current item's data from the dataset
const currentItem = szakemberekDataset.getCurrentItem();
// Log the current item's data to inspect its structure
console.log('Current Item:', currentItem);
// Get the feedback array
const feedbackArray = currentItem.feedbackArray;
// Log the feedback array to inspect its content
console.log('Feedback Array:', feedbackArray);
// Check if the feedback array exists and has items
if (feedbackArray && feedbackArray.length > 0) {
// Populate the repeater with feedback items
const repeaterData = feedbackArray.map(feedback => ({ feedbackText: feedback }));
// Log the repeater data to inspect its content
console.log('Repeater Data:', repeaterData);
// Set the repeater data
$w('#feedbackRepeater').data = repeaterData;
// Bind the feedback text to the repeater's text element
$w('#feedbackRepeater').onItemReady(($item, itemData) => {
// Log itemData to inspect its structure
console.log('Item Data:', itemData);
// Ensure the text element exists before trying to set its text
const textElement = $item('#feedbackText');
if (textElement) {
console.log('Setting text for item:', itemData.feedbackText);
textElement.text = itemData.feedbackText;
} else {
console.error('Text element not found in repeater item');
}
});
} else {
// If no feedbacks are found, clear the repeater
console.log('No feedbacks found');
$w('#feedbackRepeater').data = [];
}
});
});
$w.onReady(() => {
populateFeedbackRepeater();
});
function populateFeedbackRepeater() {
// Query the dataset connected to the Szakemberek collection
const dataset = $w('#szakemberekDataset'); // Ensure this matches your dataset ID
dataset.onReady(() => {
const currentItem = dataset.getCurrentItem();
console.log('Current Item:', currentItem);
const feedbackArray = currentItem.feedbackArray;
console.log('Feedback Array:', feedbackArray);
if (feedbackArray && feedbackArray.length > 0) {
const repeaterData = feedbackArray.map(feedback => ({ feedbackText: feedback }));
console.log('Repeater Data:', repeaterData);
$w('#feedbackRepeater').data = repeaterData;
$w('#feedbackRepeater').onItemReady(($item, itemData) => {
console.log('Item Data:', itemData);
const textElement = $item('#feedbackText');
if (textElement) {
console.log('Setting text for item:', itemData.feedbackText);
textElement.text = itemData.feedbackText;
} else {
console.error('Text element not found in repeater item');
}
});
} else {
console.log('No feedbacks found');
$w('#feedbackRepeater').data = [];
}
});
}
Additional information:
In the log I get the following:
Current Item: Data
Feedback Array Data:
0: “text1”
1: “text2”
2: “text3”
Repeater Data:
Array(3)
0: “text1”
1: “text2”
2: “text3”
Problem: not working, the repeater text doesn’t show the dataset data.