Conditionally Collapse or Hide Repeater Element Based on Presence or Absence of Item in Multiple Reference Field

Hello folks,

I find myself once again stumped by multiple references. I’ll try to explain this as succinctly as I can.

Relevant Collections:

  • EBTMembers: this is the custom membership database that I created for my website.
  • departmentposts: this is the database collecting the data of member-submitted posts that get displayed in a repeater, similar to a newsfeed
  • departmentpostlikes: this is the database I use to track which members like which posts. It has two important fields:
  1. “post”: this is a reference field, referencing the relevant post from the departmentposts database

  2. “likers”: this is a multiple reference field, referencing the EBTMembers who “liked” a given post.

Goal: I want to check to see if the current user is among those who have “liked” each post in the repeater. If yes, I want “fulllike” to expand. If no, I want “emptylike” to expand.

Current code (not working):
$w.onReady( function () {

$w( “#repeater1” ).onItemReady(($item, itemData, index) =>{

wixData.query( “EBTMembers” )
.eq( “_owner” , wixUsers.currentUser.id)
.find()
.then( (results) => {

wixData.isReferenced( “EBTMembers” , “departmentpostlikes” , results.items[ 0 ]._id, itemData.id)
.then( (result3) => {
let isReferenced3 = result3;
if (isReferenced3 === true ) {

  $item( "#fulllike" ).expand() 
  $item( "#emptylike" ).collapse()} 

else {
$item( “#fulllike” ).collapse()
$item( “#emptylike” ).expand()
}
})})})})

Any ideas?

In case it’s helpful to others, I simplified my case by just adding a multiple reference field for “likers” directly to the “departmentpost” collection, and then was able to display a full heart if the current member liked the post using:

$w.onReady( function () {

$w( “#repeater1” ).onItemReady(($item, itemData) =>{

$w( “#dataset10” ).onReady( () => {
wixData.query( “EBTMembers” )
.eq( “_owner” , wixUsers.currentUser.id)
.find()
.then( (results) => {

wixData.isReferenced( “departmentposts” , “likers” , itemData, results.items[ 0 ]._id)
.then( (result) => {
let isReferenced = result; // true

if (isReferenced === true ) {

  $item( "#fulllike" ).expand() 
  $item( "#emptylike" ).collapse() 
} 

else {
$item( “#fulllike” ).collapse()
$item( “#emptylike” ).expand()
}
})})})})})