I have a repeater that searches for all user profiles in the "Profile" database
export function repetidorAtualiza() { wixData.query("perfil") .find() .then((results) => { $w("#repeaterPerfis").data = results.items; }) .catch((error) => { let errorMsg = error.message; let code = error.code; }); $w("#repeaterPerfis").onItemReady(function ($w, itemData, index) { $w('#textNickname').text = itemData.nickname; $w('#textDescricao').text = itemData.descricao; $w('#imagePicture').src = itemData.picture; }); }
So far so good!
I am making a query in the Relationship database to know if the user is following the profile or not. The result should appear on a button (if query result> 0 then is follower, if not, enable follow button). However some buttons do not appear in the repeater when the code is called in onReady, only when placed in an onClick function.
Is there any missing data treatment for onReady consultation?
export function relacionamento() { $w("#repeaterPerfis").onItemReady(function ($w, itemData, index) { let consultaSeguindo = wixData.query("Relacionamento") .eq("seguindo", itemData._id) let consultaSeguidores = wixData.query("Relacionamento") .eq("seguidores", wixUsers.currentUser.id) consultaSeguidores.and(consultaSeguindo) .find() .then(function (results) { if (results.totalCount > 0) { $w("#buttonSeguindo").show(); $w("#buttonSeguir").hide(); } else { $w("#buttonSeguindo").hide(); $w("#buttonSeguir").show(); } console.log(results.length) }) .catch((error) => { let errorMsg = error.message; let code = error.code; }); }); }