With invaluable help from Yisrael, I’ve got my infinite scroll Repeater working. There are only two remaining problems:
-
Now that the Repeater is disconnected from the Dataset, the button on each item doesn’t link to the correct item on the database. I’m not sure how to code for this.
-
I can’t get the code to show a ‘No items found’ message. I thought it would be simple enough to code if (results.items.length < 1) {$w(‘#searchFail’).show()}
but I can’t find a place to put it. Here’s the code for the search:
async function search1 ( limit , skip ) {
searchType = 1 ;
$w ( ‘#searchFail’ ). hide ();
$w ( ‘#textClassics’ ). hide ();
try {
const results = await wixData . query ( ‘authorpages’ )
. limit ( limit )
. skip ( limit * skip )
. descending ( “likes” )
. contains ( ‘fullName’ , $w ( “#name” ). value )
. or ( wixData . query ( ‘authorpages’ )
. eq ( ‘email’ , $w ( “#email” ). value ))
. find ();
return results . items || [];
}
catch ( err ) {
console . error ( err );
}
}
$w.onItemReady(()=>{
$w('#myRepeaterIDhere').data = search1(limit, skip);
$w('#myRepeaterIDhere').onItemReady(($item, itemData, index)=>{
console.log(index);
console.log(itemData);
$item("#repeatedElementIDhere").......continue
});
});
async function search1(limit, skip) {
searchType = 1; $w('#searchFail, #textClassics').hide();
try {
const results = await wixData.query('authorpages')
.limit(limit)
.skip(limit * skip)
.descending("likes")
.contains('fullName', $w("#name").value)
.or (wixData.query('authorpages')
.eq ('email', $w("#email").value))
.find();
// Generate here your ---> IF-ELSE-STATEMENT for found or not found ITEMS...
.then((res)=>{console.log(res);
if(res) {}
else {}
// bla bla bla
})
.catch((err)=>{console.log(err)});
return results.items || [];
}
catch(err) {console.error(err);}
}
Sorry, but apart from hiding two field in a single command rather than separately, I can’t see any difference to my code.
Thanks, but there seems to be some kind of compatibility problem. With the new code I get an error in the routine that calls the search. The line
if ( moreData . length < loadLimit ) { finishLoad = true ; }
puts a red line under .length with the message 'property ‘length’ does not exist on type ‘void’. This is the same problem I was getting with my attempts.
Is it perhaps not possible to use if/else statements inside a ‘try’?
I think I’ve solved the ‘no items found’ message problem. I just put the following code in the module which calls the search:
if ( moreData . length < 1 && skip < 1 ) {
$w ( ‘#searchFail’ ). show ();
}
However, I still have the more important problem of the inoperative buttons on the Repeater items.
Just one of those weekends!
Sorry, but i do not see your current code, perhaps i am already skilled in JS, but i am not a …
Keep trying, these are the weekends where you will learn the most. Best learning method —> learning by doing.