Unfortunately, though not incorrect, Yevheniia 's response doesn’t pertain to the Gift Quiz example, which Tim is referring to: https://www.wix.com/velo/example/gift-quiz
When I use the .limit (3) function on the query result, it does then limit the results to only 3, but then you always get the same 3 results, no matter what answers you select. eg:
async function getProductsData(productsIds) {
// Query the "Products" collection for products whose ID is one of the specified IDs.
const productsData = await wixData.query("Stores/Products")
.limit(3)
.hasSome("_id", productsIds)
.find();
// Return the matching products.
return productsData.items;
}
It appears the .limit(3) overrides the getRandomItemsFromArray function?
According to the Gift Quiz example tutorial video, we should be able to limit the number of items displayed under the getRandomItemsFromArray using numberOfItems:
// Get a specified number of random items from the specified array.
function getRandomItemsFromArray(productsArr, numberOfItems){
// List for storing the randomly selected products.
const productsIds = [];
// Number of products in the specified array.
const numberOfProducts = productsArr.length;
// For specified the number of items or the number of products that were specified, whichever is lower:
for (let i = 0; i < (numberOfItems && i < numberOfProducts); i++){
// Get a random valid index.
const randomIndex = getRandomInt(0, numberOfProducts -1 );
// Add the product at that random index to the list of selected products.
productsIds.push(productsArr[randomIndex]);
// Remove the already selected product from the list of products to select from.
productsIds.splice(randomIndex, 1);
}
// Return the randomly selected products.
return productsIds;
}
In the tutorial the Wix guide says (video timestamp 08:12: https://youtu.be/qZCRivHafeQ?t=492 or see Step 8 on this Wix Tutorial here: https://support.wix.com/en/article/velo-tutorial-adding-a-gift-quiz-to-a-wix-stores-site),
“For this example, we set the number of displayed items to the number of slides in the slideshow.”
But they don’t clarify how or where. Also, I notice on the Gift Quiz Example page, the number of results (up to 10 products available in the database) often comes back higher than the number of slides (only 3 slides total) in the quiz. So, it’s not entirely clear what they mean by the above quote.
However, it appears the “numberofItems” is declared on this line:
for (let i = 0; i < (numberOfItems && i < numberOfProducts); i++)
So, to answer @Tim’s question, “Is there a way to limit the number of repeater items?” Yes, according to the tutorial there should be and I believe it happens on this line of code “for (let i = 0; i < (numberOfItems && i < numberOfProducts); i++)”
If @Yevheniia Semenina or someone else at Wix could clarify that would be greatly appreciated!