Manage hasNext() after calling a function

Hello,
I’m not able to manage HasNext() after a function.
If I use this code it works:

wixData . query ( ‘DB’ ). eq ( ‘active’ , true )
. ne ( “lost” , true )
. limit ( 4 )
. find ()
. then ( ( resultsSearch ) => {
let result = resultsSearch ;
let hasNext = result . hasNext ();
let hasPrev = result . hasPrev ();
if ( hasNext ) {
$w ( ‘#Bnext’ ). enable ();
}
if ( hasPrev ) {
$w ( ‘#Bback’ ). enable ();
}
})

If I put the same query in a function and then I call the function from a .jsw file, it does not work since it prints that HasNext() is not a function.
I’ve checked and the function is working properly with correct results.

//inside jsw file -
export function get_Record ( ) {
return wixData . query ( ‘DB’ ). eq ( ‘active’ , true )
. ne ( “lots” , true )
. limit ( 4 )
. find ()
}
// inside jsw file +

let resultsSearch = await get_Record;

   **let**  result  =  resultsSearch ; 
  **let**  hasNext  =  result . hasNext (); 
  **let**  hasPrev  =  result . hasPrev (); 
  **if**  ( hasNext  ) { 
    $w ( '#Bnext' ). enable (); 
  } 
  **if**  ( hasPrev  ) { 
    $w ( '#Bback' ). enable (); 
  } 

})

Thanks for your help!
David

Hello David,

Why not returning if the query has next or not from the backend? For this will allow you to check if there are more results left to be rerieved.

export function getData(skip) {
    let query = wixData.query('collection').eq('property', value);
    if (skip) { query = query.skip(skip) }
    
    return query.find().then((x) => {
        return {
            items: x.items;
            hasNext: x.hasNext();
        }
    })
}

This will make the hasNext property returned from the backend a boolean so you can read it immediatelty without calling a function.

Hope this helps!~
Ahmad

Hi Ahmad,
thanks for your hint.
But I need to retrieve records from the query since I’m using them to fill a repeater.
With HasNext then I need to activate a next button to go to the next page of the repeater.
For now I have a workaround, that is using the full query in the page, but I just wanted to understand how to use HasNext after a called function for future usage.
Thanks a lot
David