Search code examples
javascriptdatabasecheckboxrepeatervelo

How to get repeater data using checkbox in WIX?


I'm showing repeater data from database.Data is showing perfectly in repeater .

Now I want to select Checkbox on one or more repeater but not working.

enter image description here

When I'm checked checkbox it should show "Air Jordan".But it is showing "Hydra".Also index value are not showing.

enter image description here

This is my code

   export function checkbox1_change(event) {
 // Add your code for this event here: 

   let myid=$w('#text32').text;
  console.log(myid);
  $w("#repeater2").onItemReady( ($item, itemData, index) => {   

 if ($w("#checkbox1").checked) {
   console.log("index:"+index);
   } else {
   console.log("no Index");
   }   

   } );

Solution

  • You need to scope the clicked item like this

    export function checkbox1_change(event) {
       let $item = $w.at(event.context);
       let myid = $item('#text32').text;
       console.log(myid);
       /*Checkbox*/
       if($item("#checkbox1").checked){
          console.log("index:"+index);
       }else{
          console.log("no Index");
       }
    }
    

    Read more about scoping items here: https://www.wix.com/corvid/forum/tips-tutorials-examples/removal-of-the-w-parameter-from-event-handlers