[SOLVED] Getting a button in a repeater to open its associated item page using code???

HI,

I have seen many posts around this subject but I just cant get it to work.

I have the standard two dynamic pages (All & List page) on my site and I am trying to code the repeater so as the button “Read more” opens the linked page.

Simple enough not using code but is proving not so easy for me using code.

Here is my page code all is working perfectly retrieving the data for repeater just the button on click part does not work.

function  repeater  ( ){ 

    $w ( "#checkinsrepeater" ). onItemReady ( ( $item ,  itemData ,  index ) => {  // Gets tdata set ready 

    $item ( "#nameText" ). text  =  itemData . name ; 
    $item ( "#frontImage" ). src  =  itemData . frontPhoto ; 
    $item ( "#backImage" ). src  =  itemData . backPhoto ; 
    $item ( "#weightText" ). text  =  itemData . weightInKg . toLocaleString ( 'en' );  
    $item ( "#weightDifftext" ). text  =  itemData . weightDifference ; 
    $item ( "#tWchangetext" ). text  =  itemData . totalWeightChange ; 
    $item ( "#descriptionText" ). text  =  itemData . howDidYouFeelThisWeek ; 
    $item ( '#MoreButton' ). onClick (( event ,  $w ) =>{ 

        wixLocation . to ( "/link-check-ins-2-checkinId" ); 
        console . log  ( "Check-In Page = " ) +  itemData . link - check - ins - 2 - checkinId ; 
                                
    }) 

    //console.log('/Check-Ins/' + itemData.link-check-ins-checkinId; 
        
    console . log ( "Weight In KG = " ) +  itemData . weightInKg ; 
    
    $w ( '#titleText' ). text  =  "All Check-ins" ; 
    $w ( '#titleDesciptiontext' ). text  =  "Here you can view all your client check ins (Click on a read more to open full view)" ; 

}); 

I want the page to link to the below location.

the Field key for that column is link - check - ins - 2 - checkinId

How do I get the button to take me to that page in the code?

Hi,
try to put the button onClick() function outside the repeater onItemReady() function.

After this modify the content like this:

$w('#MoreButton').onClick((event)=>{
        let $item = event.context
        let index = $w('#checkinsrepeater').data.findIndex((repeaterItem)=>{return repeaterItem._id===$item.itemId })
        let itemData = $w('#checkinsrepeater').data[index]
        wixLocation.to(itemData.link-check-ins-2-checkinId);
    })

I’m quite sure there is a more efficient way to achieve this but should work.

I don’t belive that this will work…

wixLocation.to(itemData.link-check-ins-2-checkinId);

…instead use the following…

wixLocation.to(itemData["link-check-ins-2-checkinId"]);

Actually true, thanks for noticing

Thanks yes that works perfectly thank you guys

$w ( ‘#MoreButton’ ). onClick (( event )=>{
let $item = event . context
let index = $w ( ‘#checkinsrepeater’ ). data . findIndex (( repeaterItem )=>{ return repeaterItem . _id === $item . itemId })
let itemData = $w ( ‘#checkinsrepeater’ ). data [ index ]
wixLocation . to ( itemData [ “link-check-ins-2-checkinId” ]);
})