Showing Button In A Repeater According To Database Value.

Hello !
Hope you are fine !

Here is my code of light box ,where there is a form, to submit status (text) to database —

$w.onReady(function () {
 //TODO: write your page related code here...

});
import wixData from 'wix-data';
import wixUsers from 'wix-users';
export function button2_click(event) {
 let user = wixUsers.currentUser;
 let userId = user.id;           
 let isLoggedIn = user.loggedIn;

if (isLoggedIn) {
wixData.query("Members/PrivateMembersData")
.eq("_id", wixUsers.currentUser.id)
 .find()
        .then((results1) => {

 let toInsert = {
 "fullName":  results1.items[0].firstName,
 "userId" : userId
  };
  wixData.insert("UserStatuses", toInsert)
    .then( (results) => {
 let item = results; //see item below
    } )
    .catch( (err) => {
 let errorMsg = err;
    } );
 
  })
}

}

Now code of my page where there is a repeater. Inside it a button and some more elements —

import wixUsers from 'wix-users';

$w.onReady(function () {
 let user = wixUsers.currentUser;
 let userId = user.id;
    $w("#dataset2").onReady(() => {
        $w("#repeater1").forEachItem(($w, itemData, index) => {
let item = $w("#dataset2").getCurrentItems();
let val = item.userId;

 if (val == userId) {
                $w('#button3').show();
 
            } else {
 
                $w('#button3').hide();
 
            }

        });
    });
});

import wixLocation from 'wix-location';
import wixWindow from 'wix-window';
export function button3_click(event) {
 let currentItem = $w("#dataset2").getCurrentItem();
    wixWindow.openLightbox('DELET', currentItem)
 
 
}

What I am trying to do is to –

  1. From the lightbox form, I get the userid of the member who submitted the form and insert it into database.
  2. In the 2nd page, I get the userid of the current viewing member.
  3. Then, in the repeater, the button will only show in those containers (of the repeater) that matches the userid (from the database) = current userid.

But the above mentioned code is not working.
Can anyone point out the mistake.

Thanks,
Ajith

Instead of for each item try on item ready with $item .

Instead of $w for the button, try $item.

Thanks It worked !

import wixUsers from 'wix-users';
let user = wixUsers.currentUser;
 let userId1 = user.id;
$w.onReady(function () {
 
    $w('#dataset2').onReady( () => {
      $w('#repeater1').forEachItem( ($item, itemData, index) => {
 if(itemData.userId === userId1){
 
             $item('#button3').show();
 
 
             }
 
 else {
 
              $item('#button3').hide();
          }
      } );
  } );
} );