Hi,
I have an array of objects allShuffledItems (which is the result of a query to a collection) and I’m looking to return the first fifty items from it and assign them to a repeater. The repeater below works if I assign “allShuffledItems” to it, but would like to assign the first fifty items of allShuffledItems to the repeater. Scratching my head a bit on this…
export function backend_getRepeaterData ( collection , category , country ) {
//
return wixData . query ( collection ). limit ( 1000 )
. eq ( “category” , category )
. eq ( “country” , country )
. find ()
}
/// snip
// snip
// Front end
export function shuffle ( array ) {
for ( let i = array . length - 1 ; i > 0 ; i --) {
const j = Math . floor ( Math . random () * ( i + 1 ));
[ array [ i ], array [ j ]] = [ array [ j ], array [ i ]];
}
return array ;
}
// inside the function that picks the first 50…
**let** allItems = **await** backend_getRepeaterData ( "Store" , $w ( "#categoryInput" ). value , $w ( "#countryInput" ). value )
// we could have anywhere up to 1000 results back due to a LIMIT in the backend query, so return maxResults
**let** allShuffledItems = shuffle ( allItems . items ) <<<<<< this returns an array of objects
//let firstFiftyItems = allShuffledItems
//let firstFiftyItems = []
**var** firstFiftyItems = allItems [ 0 ]
**for** ( **var** i = 0 ; i < maxResults ; i ++) {
firstFiftyItems [ i ]= allShuffledItems [ i ]
// firstFiftyItems[i] = allShuffledItems[i]
}
$w ( '#repeater1' ). data = firstFiftyItems
Thank you!