Skip to content Skip to sidebar Skip to footer

Incorrect User Profile Picture Being Displayed From Js Array - How To Address This?

Sorry for the long post, but I'm not sure the issue comes across without all the code. I'm using parse.com and the JavaScript SDK. The below code is part of my users profile page,

Solution 1:

Just found this in the featured/bounties, even though I answered it here for you, so here's my copy/pasted answer:

You're not using query.exists() the way you think you are. Also, are you just trying to check to see if the current user has a profile image? Because you can just use the .has("key") method of objects, and a user is an object. If this is in cloud code, rather than client code, you may have to fetch the user first. If it is client code, you should already have an up to date user.

You should not be extending the user object. Not necessary at all. Use the Parse.User object type, so if you're querying for users, do var query = new Parse.Query( Parse.User );

So I think what you want is something more like:

var user = Parse.User.current();
if( user.has("ProfilePic") )
{
    //Do your stuff with the imagevar imageURL = user.get("ProfilePic").url();
    $('#Image01').attr('src', imageURL);
}
else
{
    alert("Error: User does not have a 'ProfilePic' set");
}

The way your code is set up, you're just querying through all the users with profilePics and taking the first one. My code only gets the profilePic of the current user.

Post a Comment for "Incorrect User Profile Picture Being Displayed From Js Array - How To Address This?"