I have been struggling for an hour to get this working. I don’t know what I am doing wrong and need a second set of eyes.
The goal is to read a table with WixDataQuery while in the backend, and then call this function on the frontend. Once there I will load the results into a table. I put in the console check in to make sure rowsToLoad was holding data correctly (it is). The error I get is when calling the function. I’m getting “Promise<>” in the console.
The code is for a leaderboard so it organizes, limits to top 100 players, assigns a rank to each row of data and pushes out to table.
export async function get_top_players () {
let results = await wixData . query ( “GameData” )
. descending ( “pEarnings” )
. limit ( 100 )
. find ()
. then (( results ) => {
for ( var i = 0 ; i < results . length ; i ++) {
const rowsToLoad = results . items . map (( r , i ) => {
return { “pName” : r . pName , “table_index” : i + 1 , “pExp” : r . pExp , “title” : r . title , “pEarnings” : r . pEarnings }
})
console . log ( rowsToLoad ); //Data stored correct here
return rowsToLoad ;
}
});
}