Hi Wix team,
I have been playing with the example of the ratings display in these examples and have had some success in that a ratings display that I have in the repeater is now displaying the ratings but only for the latest entry, would anyone be able to point me in the right direction? I’m trying to achieve that each item has it’s own rating in the repeater.
I seem to be getting the data to the front end but can’t get the rating to display based on the ID
View the Live demo in a browser page
Open the Example template in the Wix Editor
import { getRecipes, getSearch, getRecipe, rateRecipe, getRating } from 'backend/queries';
import wixWindow from 'wix-window';
$w.onReady(function () {
$w('#photo').src = null;
$w("#repeater1").onItemReady(($w, itemData, index) => {
$w("#title").text = itemData.title;
let photo = itemData.photo;
$w('#photo').src = itemData.photo;
let id = itemData._id;
loadStatistics(id);
console.log(id);
});
$w("#container1").onClick((event) => {
wixWindow.openLightbox("RECIPE", event.context.itemId);
});
getRecipes("all").then(function (resp) {
let items = resp.items;
let recipes = [];
items.forEach(function (item) {
let recipe = { "_id": item._id, "title": item.title, "premium": item.premium, "photo": item.photo };
recipes.push(recipe);
});
$w("#repeater1").data = [];
$w("#repeater1").data = recipes;
});
});
async function loadStatistics(id) {
getRating(id)
.then(function (response) {
let stats = response.items[0];
if (stats) {
let avgRating = (Math.round(stats.rating * 10 / stats.count) / 10);
let ratings = $w('#ratingsDisplay');
ratings.rating = avgRating;
ratings.numRatings = stats.count;
$w('#ratingsDisplay').show();
} else {
$w('#ratingsDisplay').numRatings = 0;
}
})
.catch(e => {
console.log(e);
$w('#ratingsDisplay').numRatings = 0;
});
}
Thank you!