I am trying to pull a single data field from a single row of data from this collection and use it to create a simple collapse function. I’m very new to coding and wix so please help if you can and don’t be too harsh on me. lol
$w.onReady(function () {
wixData.query("multiStepRegistrationForm4")
.find()
.then( (results) => {
//The code below was my sad attempt at calling the data from the collection and doing something with it.
var verification = (results.hasOwnProperty('verified'));
if (verification === false) {
console.log('Pending should show');
$w('#peindingVerification').expand();
}else if(verification === true){console.log('Pending should not show');
$w('#peindingVerification').collapse();
}else{
$w('#peindingVerification').collapse();
}
} );
First try to understand whats going on in this code-snipet and see in cole what are the results…
$w.onReady(function () {
xxx();
})
function xxx() {
wixData.query("multiStepRegistrationForm4")
.find()
.then((results) => {
console.log(results)
let myFoundItems = results.items
let myFirstItem = results.items[0]
console.log(myFoundItems)
console.log(myFirstItem)
})
}
You are sure that your DATABSE/COLLECTION-Name is
→ “multiStepRegistrationForm4” ???
Yes the name is accurate and I can see the data that is logged in the console.
I’m trying to isolate the “verified” field in the list. Now, currently, there is only one entry in the Database. How do I ensure that item[0] is always the user’s (owner) entry and is the most recent entry?
@dweiss48285931
let ownerID = results.items[0]._owner
let userID = results.items[0]._id
console.log(ownerID)
console.log(userID)
@russian-dima Awesome! But, if the user has made several entries, how do I filter or sort the database so that the one entry that is queried is most recent? or maybe some other. The form collects a user’s awarded jiu-jitsu belts and I need some way of ensuring that their highest ranking belt is the entry that is queried.
I suppose that will require another field in the form, and then I’d have to query that to use in my user page. Any suggestions?
@russian-dima How does that limit the query results to specific users? From the data that is populated it seems to just provide the unique owner & user IDs. Does that automatically verify it is the current user’s ID? How does the owner field work?