i will need some help either with this:
I have this code, trying to hide an image if the current user id is the same as the content of the field userId (in a collection). The order i’ve placed in the code seems to be correct but it’s not working, and i really don’t know why.
Can you help me with this? or anyone else?
let user = wix Users. currentUser .id;
This is surely not correct!
results = OBJECT
user = ??? (String?)
This is how it probably should look like.
import wixData from'wix-data';
$w.onReady(()=>{
wixData.query("Miembrosqueyahanlikeado")
.eq("userId", user)
.find()
.then( (results) => {
if(results.items.length > 0) {
let firstItem = results.items[0];
if(firstItem.userID === user ) {$w('#vectorImage').hide();}
else {$w('#vectorImage').show();}
} else { }
})
.catch( (err) => {
let errorMsg = err;
});
})
And next time please use a code in code-tags (like i did) and not a pic of your code.
You should also learn to use CONSOLE, which will help you to find your own FAILURES. Look here …
import wixData from'wix-data';
$w.onReady(()=>{console.log("USER-ID: ", userId)
wixData.query("Miembrosqueyahanlikeado")
.eq("userId", user)
.find()
.then( (results) => {console.log("RESULTS :", results)
if(results.items.length > 0) {
let firstItem = results.items[0];
console.log("FIRST-ITEM :", firstItem)
if(firstItem.userID === user ) {$w('#vectorImage').hide();}
else {$w('#vectorImage').show();}
} else { }
})
.catch( (err) => {
let errorMsg = err;
});
})
I tried to use a “code snippet” as you, but the web told me that i was placing an URL… Tried to write it in different ways, but only with the image has let me send the post.
About the consol Log:
I was searching how to use the console to see the failures, but didn’t found that. Luckily you showed me how! thanks for that too!
I’ve just started learning code .js and .html, please be patient with me :D, i’m a big newbie
I use Velo Reference too, but for me it’s very difficult to understand. Individualy, i understand each command, but trying to place them together… Breaks my brain for the moment for the most part of the code.
Thanks anyway: D like last time, you have been a great help to me
- To use the full service of this forum you should do a registration.
When you did it already, you should be able to use CODE-TAGs.
Take a look at this picture…
You will find the shown menu directly on the bottom of every post you want to create.
- Yes i understand you, i started the same way, you do it right know.
Without any knowledge. Keep trying and we will do a smal-talk after about 6-month. You will see, that after a period of learning-time, you will understand more of Velo and JS and you will be able to put things together much faster and much efficient (when coding on projects).
Good luck and happy coding.
- Some facts about CONSOLE.
-the CONSOLE should be your best friend !!!
-use it as often as you can and you will recognice it’s advantages.
-There are 2 different ways how to use it.
a) CONSOLE of PREVIEW-MODE of your Wix-Editor.
b) Press F-12 in google-chrome and go to CONSOLE
Finally it work’s!!!
sorry for the image i will place but i’m logged in and still having issues with the permission to use embed code , code snippet…
This article has helped me a lot to understand the procedure: Velo: Working with the Data API | Help Center | Wix.com
Thanks to you to!!!