解析查询不会将结果限制为当前用户

时间:2015-08-12 20:08:58

标签: javascript parse-platform

使用parse.com和JS SDK。

为什么此查询不会仅将结果限制为当前用户?我用过

  

query.exists(“ProfilePic”),Parse.User.current();

我认为会这样做,但我的所有用户个人资料图片都在查询的第二部分返回,这意味着我的当前用户的个人资料图片错误。

不确定为什么会这样?

var query = new Parse.Query(Parse.User);
var user = Parse.User.current();
if( user.has("ProfilePic") )
query.find({
        success: function(results) {
            // If the query is successful, store each image URL in an array of image URL's
            imageURLs = [];
            for (var i = 0; i < results.length; i++) {
                var object = results[i];
                imageURLs.push(object.get('ProfilePic').url());
            }
            // If the imageURLs array has items in it, set the src of an IMG element to the first URL in the array
            if (imageURLs.length > 0) {
                $('#Image01').attr('src', imageURLs[0]);
            }
                $('#Image01').attr('src', imageURLs[0]); //first image
        },
        error: function(error) {
            // If the query is unsuccessful, report any errors
            alert("Error: " + error.code + " " + error.message);
        }
    });

1 个答案:

答案 0 :(得分:2)

你没有像你想象的那样使用query.exists()。此外,您是否只是想检查当前用户是否有个人资料图片?因为您可以只使用对象的<div class="navbar-userData">方法,而用户就是对象。如果这是云代码而不是客户端代码,则可能必须先获取用户。如果是客户端代码,您应该已经有了最新的用户。

您不应该扩展用户对象。根本没必要。使用Parse.User对象类型,因此如果您要查询用户,请执行.has("key")

所以我认为你想要的更像是:

var query = new Parse.Query( Parse.User );