Hi everyone,
I am new to Wix coding so please be gentle!
I have spent a day and a half looking through this site, code examples, YT videos and alike and no matter what I try I simply cannot make the code work
The idea is that a user logs into the sports site, it then takes the CurrentUser details and passes them to the dataset on the Score page; which in turn should then only show them their scores.
The first issue (which others seem to have encountered) is when the page loads it shows all members scores before the filter is applied, as the filter is applied the scores then only show the current users scores (or would do if the filter worked).
import wixData from 'wix-data';
import wixUsers from 'wix-users';
export function page1_viewportEnter(event) {
//Add your code for this event here:
}
export function button5_click(event) {
//Add your code for this event here:
$w.onReady(function () {
let name = "No user"
let user = wixUsers.currentUser;
let userid = user.id
let options = {
"suppressAuth": true,
"suppressHooks": true
};
// pull name out of PrivateMembersData (file created by default logon)
console.log(userid)
wixData.get("Members/PrivateMembersData",userid, options)
.then( (results) => {
let item = results;
name = item.name // pull out the name (by field "name")
//console.log(name) // Debugging purposes
// Now we have the name, filter the DS based on this person
$w("#MyScoresDS").setFilter(wixData.filter()
.eq('Name',name)
);
})
.catch( (err) => {
let errorMsg = err;
console.log(err);
});
});
}
On clicking the button the table the DS is attached too goes blank.
Any suggestions most welcome.