Trying to open lightbox from within a dynamic repeater

Hi all - This topic has been talked about before, and lots of times, folks are referred to this page:

I can get this code to work, but as a couple of commenters on this have said, when published, the contents appear in the correct order on the published page for just a couple of seconds, then the page refreshes and the item order goes wonky.

Here is the code snippet from that original post. Can anyone help diagnose the problem?
import wixData from ‘wix-data’ ;
import wixWindow from ‘wix-window’ ;

$w . onReady ( function (){
wixData . query ( “collectionName” )
. find ()
. then (( results ) => {
$w ( #repeater1 ). data = results . items ;
. catch (( err ) => {
let errorMsg = err ;
$w ( #repeater1 ). onItemReady (( $w, itemData ) => {
console . log ( itemData );
$w ( #button1 ). label = itemData . title ;
$w ( #button1 ). onClick (( event ) => {
wixWindow . openLightbox ( itemData . lightbox );

Thanks for any help!

Your post landet in the wrong forum-section!

Note that you should be using the Repeated Item Scope ($item) in the onItemReady() function.

Also, is your Repeater connected to a Dataset? That might be why it refreshes and changes the order. Populate the Repeater by connecting to a dataset, or by performing a query (as in the code you shared), but not both.

Thank you! I am sure that is my problem - it is connected to a dataset. I am a monkey with a razor blade here - not a coder - so I didn’t pick up that this code replaces the dataset connection. I need to go dig and do some research on just how to set the whole thing up properly when doing this type of query (for instance - I don’t know yet what your first sentence above means - lots to learn! :blush:) Thanks much for setting me in the right direction!!